mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Fix rendering mentions inside of URLs
This commit is contained in:
parent
1a98049ee8
commit
ddba16551a
2 changed files with 33 additions and 13 deletions
|
|
@ -123,21 +123,25 @@ const createStatusController: AppController = async (c) => {
|
|||
|
||||
const pubkeys = new Set<string>();
|
||||
|
||||
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 ?? '',
|
||||
/(?<![\w/])@([\w@+._]+)(?![\w/\.])/g,
|
||||
async (match, username) => {
|
||||
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 ?? []) {
|
||||
|
|
|
|||
|
|
@ -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: <a href="https://gleasonator.dev/@alex@gleasonator.dev/posts/a8badb480d88f9e7b6a090342279ef47ed0e0a3989ed85f898dfedc6be94225f">https://gleasonator.dev/@alex@gleasonator.dev/posts/a8badb480d88f9e7b6a090342279ef47ed0e0a3989ed85f898dfedc6be94225f</a>',
|
||||
);
|
||||
});
|
||||
|
||||
Deno.test('getMediaLinks', () => {
|
||||
const links = [
|
||||
{ href: 'https://example.com/image.png' },
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue