Wrap URL in a try-catch

This commit is contained in:
Alex Gleason 2024-08-28 21:15:43 +02:00
parent 043e579c10
commit 7a2a8bd4f5
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -33,10 +33,10 @@ function parseNoteContent(content: string, mentions: MastodonMention[]): ParsedN
return html`<a class="mention hashtag" href="${href}" rel="tag"><span>#</span>${tag}</a>`;
},
url: ({ attributes, content }) => {
const { protocol, pathname } = new URL(content);
try {
const { protocol, pathname } = new URL(content);
if (protocol === 'nostr:') {
try {
if (protocol === 'nostr:') {
const match = pathname.match(new RegExp(`^${nip19.BECH32_REGEX.source}`));
if (match) {
const bech32 = match[0];
@ -52,10 +52,10 @@ function parseNoteContent(content: string, mentions: MastodonMention[]): ParsedN
return html`<span class="h-card"><a class="u-url mention" href="${href}" rel="ugc">@<span>${name}</span></a></span>${extra}`;
}
}
} catch {
// fallthrough
}
return content;
} catch {
// fallthrough
}
const attr = Object.entries(attributes)