From ad88d8993d938bffb1d5c4b3033831489f2adbaa Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Thu, 22 Oct 2020 14:06:28 -0400 Subject: [PATCH] fix app crash --- ui/component/markdownLink/view.jsx | 37 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/ui/component/markdownLink/view.jsx b/ui/component/markdownLink/view.jsx index 5a00f7e30..f37c4f6e6 100644 --- a/ui/component/markdownLink/view.jsx +++ b/ui/component/markdownLink/view.jsx @@ -24,30 +24,31 @@ function MarkdownLink(props: Props) { return children || null; } + let element = {children}; + // Regex for url protocol const protocolRegex = new RegExp('^(https?|lbry|mailto)+:', 'i'); const protocol = href ? protocolRegex.exec(href) : null; + // Return plain text if no valid url - let element = {children}; // Return external link if protocol is http or https - - const linkUrlObject = new URL(decodedUri); - const linkDomain = linkUrlObject.host; - const isKnownAppDomainLink = KNOWN_APP_DOMAINS.includes(linkDomain); - let lbryUrlFromLink; - if (isKnownAppDomainLink) { - const linkPathname = decodeURIComponent( - linkUrlObject.pathname.startsWith('//') ? linkUrlObject.pathname.slice(2) : linkUrlObject.pathname.slice(1) - ); - const possibleLbryUrl = `lbry://${linkPathname.replace(/:/g, '#')}`; - const lbryLinkIsValid = isURIValid(possibleLbryUrl); - if (lbryLinkIsValid) { - lbryUrlFromLink = possibleLbryUrl; - } - } - // Return local link if protocol is lbry uri - if ((protocol && protocol[0] === 'lbry:' && isURIValid(decodedUri)) || lbryUrlFromLink) { + if (protocol && protocol[0] === 'lbry:' && isURIValid(decodedUri)) { + const linkUrlObject = new URL(decodedUri); + const linkDomain = linkUrlObject.host; + const isKnownAppDomainLink = KNOWN_APP_DOMAINS.includes(linkDomain); + let lbryUrlFromLink; + if (isKnownAppDomainLink) { + const linkPathname = decodeURIComponent( + linkUrlObject.pathname.startsWith('//') ? linkUrlObject.pathname.slice(2) : linkUrlObject.pathname.slice(1) + ); + const possibleLbryUrl = `lbry://${linkPathname.replace(/:/g, '#')}`; + const lbryLinkIsValid = isURIValid(possibleLbryUrl); + if (lbryLinkIsValid) { + lbryUrlFromLink = possibleLbryUrl; + } + } + element = (