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>,
a: ({ href, children }) => {
if (href && !isInCatalogView) {
const linkMediaInfo = getLinkMediaInfo(href);
const embedUrl = new URL(href);
if (canEmbed(embedUrl) || getHasThumbnail(linkMediaInfo, href)) {
return <ContentLinkEmbed children={children} href={href} linkMediaInfo={linkMediaInfo} />;
} else {
return (
<a href={href} target='_blank' rel='noopener noreferrer'>
{children}
</a>
);
try {
const linkMediaInfo = getLinkMediaInfo(href);
const embedUrl = href.startsWith('http') ? new URL(href) : null;
if ((embedUrl && canEmbed(embedUrl)) || getHasThumbnail(linkMediaInfo, href)) {
return <ContentLinkEmbed children={children} href={href} linkMediaInfo={linkMediaInfo} />;
}
} catch (e) {
console.debug('Invalid URL:', href);
}
return (
<a href={href} target='_blank' rel='noopener noreferrer'>
{children}
</a>
);
}
},
}}