fix app crash
This commit is contained in:
parent
851b2d13e4
commit
ad88d8993d
1 changed files with 19 additions and 18 deletions
|
@ -24,30 +24,31 @@ function MarkdownLink(props: Props) {
|
||||||
return children || null;
|
return children || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let element = <span>{children}</span>;
|
||||||
|
|
||||||
// Regex for url protocol
|
// Regex for url protocol
|
||||||
const protocolRegex = new RegExp('^(https?|lbry|mailto)+:', 'i');
|
const protocolRegex = new RegExp('^(https?|lbry|mailto)+:', 'i');
|
||||||
const protocol = href ? protocolRegex.exec(href) : null;
|
const protocol = href ? protocolRegex.exec(href) : null;
|
||||||
|
|
||||||
// Return plain text if no valid url
|
// Return plain text if no valid url
|
||||||
let element = <span>{children}</span>;
|
|
||||||
// Return external link if protocol is http or https
|
// 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
|
// 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 = (
|
element = (
|
||||||
<ClaimLink
|
<ClaimLink
|
||||||
uri={lbryUrlFromLink || decodedUri}
|
uri={lbryUrlFromLink || decodedUri}
|
||||||
|
|
Loading…
Add table
Reference in a new issue