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.
This commit is contained in:
Sam Samskies 2023-03-14 15:38:14 -05:00
parent 2b0cd75f98
commit e4e5913c40
No known key found for this signature in database
GPG Key ID: E3F697EE1B6EB156

View File

@ -58,7 +58,7 @@ export default function useEventPublisher() {
return match;
}
};
const replaceNoteId = (match: string) => {
const replaceNoteId = (_: string, match: string) => {
try {
const hex = bech32ToHex(match);
const idx = ev.Tags.length;
@ -76,7 +76,7 @@ export default function useEventPublisher() {
};
const content = msg
.replace(/@npub[a-z0-9]+/g, replaceNpub)
.replace(/note1[acdefghjklmnpqrstuvwxyz023456789]{58}/g, replaceNoteId)
.replace(/\s(note1[acdefghjklmnpqrstuvwxyz023456789]{58})\s/g, replaceNoteId)
.replace(HashtagRegex, replaceHashtag);
ev.Content = content;
}