fix(markdown): invalid urls in content could crash the app

This commit is contained in:
Tom (plebeius.eth)
2024-11-17 15:59:59 +01:00
parent 24816c6aa8
commit 73bab13e34
+14 -10
View File
@@ -179,17 +179,21 @@ const Markdown = ({ content, title }: MarkdownProps) => {
source: ({ src }) => <span>{src}</span>, source: ({ src }) => <span>{src}</span>,
a: ({ href, children }) => { a: ({ href, children }) => {
if (href && !isInCatalogView) { if (href && !isInCatalogView) {
const linkMediaInfo = getLinkMediaInfo(href); try {
const embedUrl = new URL(href); const linkMediaInfo = getLinkMediaInfo(href);
if (canEmbed(embedUrl) || getHasThumbnail(linkMediaInfo, href)) { const embedUrl = href.startsWith('http') ? new URL(href) : null;
return <ContentLinkEmbed children={children} href={href} linkMediaInfo={linkMediaInfo} />; if ((embedUrl && canEmbed(embedUrl)) || getHasThumbnail(linkMediaInfo, href)) {
} else { return <ContentLinkEmbed children={children} href={href} linkMediaInfo={linkMediaInfo} />;
return ( }
<a href={href} target='_blank' rel='noopener noreferrer'> } catch (e) {
{children} console.debug('Invalid URL:', href);
</a>
);
} }
return (
<a href={href} target='_blank' rel='noopener noreferrer'>
{children}
</a>
);
} }
}, },
}} }}