Fix rendering mentions inside of URLs

This commit is contained in:
Alex Gleason 2024-09-07 09:41:29 -05:00
parent 1a98049ee8
commit ddba16551a
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 33 additions and 13 deletions

View file

@ -123,7 +123,10 @@ const createStatusController: AppController = async (c) => {
const pubkeys = new Set<string>(); const pubkeys = new Set<string>();
const content = await asyncReplaceAll(data.status ?? '', /@([\w@+._]+)/g, async (match, username) => { const content = await asyncReplaceAll(
data.status ?? '',
/(?<![\w/])@([\w@+._]+)(?![\w/\.])/g,
async (match, username) => {
const pubkey = await lookupPubkey(username); const pubkey = await lookupPubkey(username);
if (!pubkey) return match; if (!pubkey) return match;
@ -137,7 +140,8 @@ const createStatusController: AppController = async (c) => {
} catch { } catch {
return match; return match;
} }
}); },
);
// Explicit addressing // Explicit addressing
for (const to of data.to ?? []) { for (const to of data.to ?? []) {

View file

@ -49,6 +49,22 @@ Deno.test('parseNoteContent renders empty for non-profile nostr URIs', () => {
assertEquals(html, ''); 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: <a href="https://gleasonator.dev/@alex@gleasonator.dev/posts/a8badb480d88f9e7b6a090342279ef47ed0e0a3989ed85f898dfedc6be94225f">https://gleasonator.dev/@alex@gleasonator.dev/posts/a8badb480d88f9e7b6a090342279ef47ed0e0a3989ed85f898dfedc6be94225f</a>',
);
});
Deno.test('getMediaLinks', () => { Deno.test('getMediaLinks', () => {
const links = [ const links = [
{ href: 'https://example.com/image.png' }, { href: 'https://example.com/image.png' },