mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Hide non-profile nostr URIs from text
This commit is contained in:
parent
ba77787767
commit
0b6ca9dfea
2 changed files with 14 additions and 3 deletions
|
|
@ -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>'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>'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' },
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,13 @@ 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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue