mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-23 17:47:24 +00:00
fix page crash on mailto links
This commit is contained in:
parent
dc3fac6a4c
commit
d408b0fd96
1 changed files with 13 additions and 23 deletions
|
@ -1,6 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
import { KNOWN_APP_DOMAINS } from 'config';
|
import { KNOWN_APP_DOMAINS } from 'config';
|
||||||
import * as MODALS from 'constants/modal_types';
|
|
||||||
import * as ICONS from 'constants/icons';
|
import * as ICONS from 'constants/icons';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { isURIValid } from 'lbry-redux';
|
import { isURIValid } from 'lbry-redux';
|
||||||
|
@ -12,24 +11,15 @@ type Props = {
|
||||||
title?: string,
|
title?: string,
|
||||||
embed?: boolean,
|
embed?: boolean,
|
||||||
children: React.Node,
|
children: React.Node,
|
||||||
openModal: (id: string, { uri: string }) => void,
|
|
||||||
parentCommentId?: string,
|
parentCommentId?: string,
|
||||||
isMarkdownPost?: boolean,
|
isMarkdownPost?: boolean,
|
||||||
simpleLinks?: boolean,
|
simpleLinks?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
function MarkdownLink(props: Props) {
|
function MarkdownLink(props: Props) {
|
||||||
const {
|
const { children, href, title, embed = false, parentCommentId, isMarkdownPost, simpleLinks = false } = props;
|
||||||
children,
|
|
||||||
href,
|
|
||||||
title,
|
|
||||||
embed = false,
|
|
||||||
openModal,
|
|
||||||
parentCommentId,
|
|
||||||
isMarkdownPost,
|
|
||||||
simpleLinks = false,
|
|
||||||
} = props;
|
|
||||||
const decodedUri = decodeURI(href);
|
const decodedUri = decodeURI(href);
|
||||||
|
|
||||||
if (!href) {
|
if (!href) {
|
||||||
return children || null;
|
return children || null;
|
||||||
}
|
}
|
||||||
|
@ -50,14 +40,18 @@ function MarkdownLink(props: Props) {
|
||||||
const linkDomain = linkUrlObject.host;
|
const linkDomain = linkUrlObject.host;
|
||||||
const isKnownAppDomainLink = KNOWN_APP_DOMAINS.includes(linkDomain);
|
const isKnownAppDomainLink = KNOWN_APP_DOMAINS.includes(linkDomain);
|
||||||
if (isKnownAppDomainLink) {
|
if (isKnownAppDomainLink) {
|
||||||
const linkPathname = decodeURIComponent(
|
let linkPathname;
|
||||||
|
try {
|
||||||
|
// This could be anything
|
||||||
|
linkPathname = decodeURIComponent(
|
||||||
linkUrlObject.pathname.startsWith('//') ? linkUrlObject.pathname.slice(2) : linkUrlObject.pathname.slice(1)
|
linkUrlObject.pathname.startsWith('//') ? linkUrlObject.pathname.slice(2) : linkUrlObject.pathname.slice(1)
|
||||||
);
|
);
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
const linkPathPlusHash = linkPathname + linkUrlObject.hash;
|
const linkPathPlusHash = linkPathname ? `${linkPathname}${linkUrlObject.hash}` : undefined;
|
||||||
const possibleLbryUrl = `lbry://${linkPathPlusHash.replace(/:/g, '#')}`;
|
const possibleLbryUrl = linkPathPlusHash ? `lbry://${linkPathPlusHash.replace(/:/g, '#')}` : undefined;
|
||||||
|
|
||||||
const lbryLinkIsValid = isURIValid(possibleLbryUrl);
|
const lbryLinkIsValid = possibleLbryUrl && isURIValid(possibleLbryUrl);
|
||||||
if (lbryLinkIsValid) {
|
if (lbryLinkIsValid) {
|
||||||
lbryUrlFromLink = possibleLbryUrl;
|
lbryUrlFromLink = possibleLbryUrl;
|
||||||
}
|
}
|
||||||
|
@ -92,11 +86,7 @@ function MarkdownLink(props: Props) {
|
||||||
label={children}
|
label={children}
|
||||||
className="button--external-link"
|
className="button--external-link"
|
||||||
navigate={isLbryLink ? href : undefined}
|
navigate={isLbryLink ? href : undefined}
|
||||||
onClick={() => {
|
href={isLbryLink ? undefined : href}
|
||||||
if (!isLbryLink) {
|
|
||||||
openModal(MODALS.CONFIRM_EXTERNAL_RESOURCE, { uri: href, isTrusted: false });
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue