mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(markdown): invalid urls in content could crash the app
This commit is contained in:
@@ -179,18 +179,22 @@ 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) {
|
||||||
|
try {
|
||||||
const linkMediaInfo = getLinkMediaInfo(href);
|
const linkMediaInfo = getLinkMediaInfo(href);
|
||||||
const embedUrl = new URL(href);
|
const embedUrl = href.startsWith('http') ? new URL(href) : null;
|
||||||
if (canEmbed(embedUrl) || getHasThumbnail(linkMediaInfo, href)) {
|
if ((embedUrl && canEmbed(embedUrl)) || getHasThumbnail(linkMediaInfo, href)) {
|
||||||
return <ContentLinkEmbed children={children} href={href} linkMediaInfo={linkMediaInfo} />;
|
return <ContentLinkEmbed children={children} href={href} linkMediaInfo={linkMediaInfo} />;
|
||||||
} else {
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.debug('Invalid URL:', href);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a href={href} target='_blank' rel='noopener noreferrer'>
|
<a href={href} target='_blank' rel='noopener noreferrer'>
|
||||||
{children}
|
{children}
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user