Hide non-profile nostr URIs from text

This commit is contained in:
Alex Gleason 2024-08-28 21:24:50 +02:00
parent ba77787767
commit 0b6ca9dfea
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 14 additions and 3 deletions

View file

@ -32,15 +32,23 @@ Deno.test('parseNoteContent parses mentions with apostrophes', () => {
); );
assertEquals( assertEquals(
html, html,
`did you see <span class="h-card"><a class="u-url mention" href="https://gleasonator.dev/@alex" rel="ugc">@<span>alex@gleasonator.dev</span></a></span>&apos;s speech?`, 'did you see <span class="h-card"><a class="u-url mention" href="https://gleasonator.dev/@alex" rel="ugc">@<span>alex@gleasonator.dev</span></a></span>&apos;s speech?',
); );
}); });
Deno.test("parseNoteContent doesn't parse invalid nostr URIs", () => { Deno.test("parseNoteContent doesn't parse invalid nostr URIs", () => {
const { html } = parseNoteContent(`nip19 has URIs like nostr:npub and nostr:nevent, etc.`, []); const { html } = parseNoteContent('nip19 has URIs like nostr:npub and nostr:nevent, etc.', []);
assertEquals(html, 'nip19 has URIs like nostr:npub and nostr:nevent, etc.'); assertEquals(html, 'nip19 has URIs like nostr:npub and nostr:nevent, etc.');
}); });
Deno.test('parseNoteContent renders empty for non-profile nostr URIs', () => {
const { html } = parseNoteContent(
'nostr:nevent1qgsr9cvzwc652r4m83d86ykplrnm9dg5gwdvzzn8ameanlvut35wy3gpz3mhxue69uhhztnnwashymtnw3ezucm0d5qzqru8mkz2q4gzsxg99q7pdneyx7n8p5u0afe3ntapj4sryxxmg4gpcdvgce',
[],
);
assertEquals(html, '');
});
Deno.test('getMediaLinks', () => { Deno.test('getMediaLinks', () => {
const links = [ const links = [
{ href: 'https://example.com/image.png' }, { href: 'https://example.com/image.png' },

View file

@ -50,9 +50,12 @@ function parseNoteContent(content: string, mentions: MastodonMention[]): ParsedN
const name = mention?.acct ?? npub.substring(0, 8); const name = mention?.acct ?? npub.substring(0, 8);
const href = mention?.url ?? Conf.local(`/@${acct}`); const href = mention?.url ?? Conf.local(`/@${acct}`);
return html`<span class="h-card"><a class="u-url mention" href="${href}" rel="ugc">@<span>${name}</span></a></span>${extra}`; return html`<span class="h-card"><a class="u-url mention" href="${href}" rel="ugc">@<span>${name}</span></a></span>${extra}`;
} else {
return '';
} }
} else {
return content;
} }
return content;
} }
} catch { } catch {
// fallthrough // fallthrough