From 84ad3556a767b170131c302a412aa9a20d54ad27 Mon Sep 17 00:00:00 2001 From: Sam Samskies Date: Wed, 15 Mar 2023 15:02:54 -1000 Subject: [PATCH] only replace note ID when note ID starts with `@` character (#441) * only replace note ID when note ID is surrounded by space chars This prevents partial parts of links with note IDs from being converted to a tag. * make sure to keep whitespace around note ID * improve var name * allow users to prefix note ID with an @ * require notes to be prefixed with `@` --- packages/app/src/Feed/EventPublisher.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/app/src/Feed/EventPublisher.ts b/packages/app/src/Feed/EventPublisher.ts index b8c53a4..1d5eaf2 100644 --- a/packages/app/src/Feed/EventPublisher.ts +++ b/packages/app/src/Feed/EventPublisher.ts @@ -59,8 +59,9 @@ export default function useEventPublisher() { } }; const replaceNoteId = (match: string) => { + const noteId = match.slice(1); try { - const hex = bech32ToHex(match); + const hex = bech32ToHex(noteId); const idx = ev.Tags.length; ev.Tags.push(new Tag(["e", hex, "", "mention"], idx)); return `#[${idx}]`; @@ -76,7 +77,7 @@ export default function useEventPublisher() { }; const content = msg .replace(/@npub[a-z0-9]+/g, replaceNpub) - .replace(/note1[acdefghjklmnpqrstuvwxyz023456789]{58}/g, replaceNoteId) + .replace(/@note1[acdefghjklmnpqrstuvwxyz023456789]{58}/g, replaceNoteId) .replace(HashtagRegex, replaceHashtag); ev.Content = content; }