From e2454405ad8c1c4529fd17da48c99c932df93d8e Mon Sep 17 00:00:00 2001 From: codytseng Date: Sat, 5 Apr 2025 11:17:37 +0800 Subject: [PATCH] fix: only add nostr: for valid nip19 --- src/components/PostEditor/utils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/components/PostEditor/utils.ts b/src/components/PostEditor/utils.ts index e4ee7bfe..98dfe718 100644 --- a/src/components/PostEditor/utils.ts +++ b/src/components/PostEditor/utils.ts @@ -1,6 +1,13 @@ +import { nip19 } from 'nostr-tools' + export function preprocessContent(content: string) { const regex = /(?<=^|\s)(nevent|naddr|nprofile|npub)[a-zA-Z0-9]+/g return content.replace(regex, (match) => { - return `nostr:${match}` + try { + nip19.decode(match) + return `nostr:${match}` + } catch { + return match + } }) }