Skip to content

Commit c2423f7

Browse files
committed
nip27: fix hashtag parsing after newline or other characters.
1 parent 05b1fba commit c2423f7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

nip27.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ test('parse content with hashtags and emoji shortcodes', () => {
8585
['emoji', 'alpaca', 'https://example.com/alpaca.png'],
8686
],
8787
content:
88-
'hey nostr:npub1hpslpc8c5sp3e2nhm2fr7swsfqpys5vyjar5dwpn7e7decps6r8qkcln63 check out :alpaca::alpaca: #alpaca at wss://alpaca.com! :star:',
88+
'hey nostr:npub1hpslpc8c5sp3e2nhm2fr7swsfqpys5vyjar5dwpn7e7decps6r8qkcln63 check out :alpaca::alpaca: #alpaca at wss://alpaca.com! :star:\n\n#WORDS #486 5/6',
8989
created_at: 1234567890,
9090
pubkey: 'dummy',
9191
id: 'dummy',
@@ -105,6 +105,11 @@ test('parse content with hashtags and emoji shortcodes', () => {
105105
{ type: 'relay', url: 'wss://alpaca.com/' },
106106
{ type: 'text', text: '! ' },
107107
{ type: 'emoji', shortcode: 'star', url: 'https://example.com/star.png' },
108+
{ type: 'text', text: '\n\n' },
109+
{ type: 'hashtag', value: 'WORDS' },
110+
{ type: 'text', text: ' ' },
111+
{ type: 'hashtag', value: '486' },
112+
{ type: 'text', text: ' 5/6' },
108113
])
109114
})
110115

nip27.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function* parse(content: string | NostrEvent): Iterable<Block> {
6969

7070
if (u === -1 || (h >= 0 && h < u)) {
7171
// parse hashtag
72-
if (h === 0 || content[h - 1] === ' ') {
72+
if (h === 0 || content[h - 1].match(noCharacter)) {
7373
const m = content.slice(h + 1, h + MAX_HASHTAG_LENGTH).match(noCharacter)
7474
const end = m ? h + 1 + m.index! : max
7575
yield { type: 'text', text: content.slice(prevIndex, h) }

0 commit comments

Comments
 (0)