Fix event mention bug (#421)

* only replace valid note IDs

* render empty string if no ref.Event
This commit is contained in:
Sam Samskies 2023-03-10 06:08:59 -10:00 committed by GitHub
parent 1357b7a903
commit 3dccf21d2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -81,13 +81,15 @@ export default function Text({ content, tags, creator }: TextProps) {
}
case "e": {
const eText = hexToBech32("note", ref.Event).substring(0, 12);
return (
return ref.Event ? (
<Link
to={eventLink(ref.Event ?? "")}
to={eventLink(ref.Event)}
onClick={e => e.stopPropagation()}
state={{ from: location.pathname }}>
#{eText}
</Link>
) : (
""
);
}
case "t": {

View File

@ -76,7 +76,7 @@ export default function useEventPublisher() {
};
const content = msg
.replace(/@npub[a-z0-9]+/g, replaceNpub)
.replace(/note[a-z0-9]+/g, replaceNoteId)
.replace(/note1[acdefghjklmnpqrstuvwxyz023456789]{58}/g, replaceNoteId)
.replace(HashtagRegex, replaceHashtag);
ev.Content = content;
}