diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index 621e26a8..282698e3 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -123,21 +123,25 @@ const createStatusController: AppController = async (c) => { const pubkeys = new Set(); - const content = await asyncReplaceAll(data.status ?? '', /@([\w@+._]+)/g, async (match, username) => { - const pubkey = await lookupPubkey(username); - if (!pubkey) return match; + const content = await asyncReplaceAll( + data.status ?? '', + /(? { + const pubkey = await lookupPubkey(username); + if (!pubkey) return match; - // Content addressing (default) - if (!data.to) { - pubkeys.add(pubkey); - } + // Content addressing (default) + if (!data.to) { + pubkeys.add(pubkey); + } - try { - return `nostr:${nip19.npubEncode(pubkey)}`; - } catch { - return match; - } - }); + try { + return `nostr:${nip19.npubEncode(pubkey)}`; + } catch { + return match; + } + }, + ); // Explicit addressing for (const to of data.to ?? []) { diff --git a/src/utils/note.test.ts b/src/utils/note.test.ts index 39be190b..e8d17e89 100644 --- a/src/utils/note.test.ts +++ b/src/utils/note.test.ts @@ -49,6 +49,22 @@ Deno.test('parseNoteContent renders empty for non-profile nostr URIs', () => { assertEquals(html, ''); }); +Deno.test("parseNoteContent doesn't fuck up links to my own post", () => { + const { html } = parseNoteContent( + 'Check this post: https://gleasonator.dev/@alex@gleasonator.dev/posts/a8badb480d88f9e7b6a090342279ef47ed0e0a3989ed85f898dfedc6be94225f', + [{ + id: '0461fcbecc4c3374439932d6b8f11269ccdb7cc973ad7a50ae362db135a474dd', + username: 'alex', + acct: 'alex@gleasonator.dev', + url: 'https://gleasonator.dev/@alex', + }], + ); + assertEquals( + html, + 'Check this post: https://gleasonator.dev/@alex@gleasonator.dev/posts/a8badb480d88f9e7b6a090342279ef47ed0e0a3989ed85f898dfedc6be94225f', + ); +}); + Deno.test('getMediaLinks', () => { const links = [ { href: 'https://example.com/image.png' },