diff --git a/jsr.json b/jsr.json index 9416218..45e05de 100644 --- a/jsr.json +++ b/jsr.json @@ -1,6 +1,6 @@ { "name": "@nostr/tools", - "version": "2.19.3", + "version": "2.19.4", "exports": { ".": "./index.ts", "./core": "./core.ts", diff --git a/nip27.test.ts b/nip27.test.ts index 7b8d1bc..dd4879c 100644 --- a/nip27.test.ts +++ b/nip27.test.ts @@ -16,14 +16,14 @@ test('first: parse simple content with 1 url and 1 nostr uri', () => { }) test('second: parse content with 3 urls of different types', () => { - const content = `:wss://oa.ao; this was a relay and now here's a video -> https://videos.com/video.mp4! and some music: + const content = `:wss://oa.ao/a/; this was a relay and now here's a video -> https://videos.com/video.mp4! and some music: http://music.com/song.mp3 and a regular link: https://regular.com/page?ok=true. and now a broken link: https://kjxkxk and a broken nostr ref: nostr:nevent1qqsr0f9w78uyy09qwmjt0kv63j4l7sxahq33725lqyyp79whlfjurwspz4mhxue69uhh56nzv34hxcfwv9ehw6nyddhq0ag9xg and a fake nostr ref: nostr:llll ok but finally https://ok.com!` const blocks = Array.from(parse(content)) expect(blocks).toEqual([ { type: 'text', text: ':' }, - { type: 'relay', url: 'wss://oa.ao/' }, + { type: 'relay', url: 'wss://oa.ao/a/' }, { type: 'text', text: "; this was a relay and now here's a video -> " }, { type: 'video', url: 'https://videos.com/video.mp4' }, { type: 'text', text: '! and some music:\n' }, @@ -113,3 +113,18 @@ test('emoji shortcodes are treated as text if no event tags', () => { expect(blocks).toEqual([{ type: 'text', text: 'hello :alpaca:' }]) }) + +test("a thing that didn't work well in the wild", () => { + const blocks = Array.from( + parse( + `Crowdsourcing doesn't mean just users clicking, by the way (although that could be possible too), it means a bunch of machines competing: https://leaderboard.sbstats.uk/`, + ), + ) + expect(blocks).toEqual([ + { + type: 'text', + text: `Crowdsourcing doesn't mean just users clicking, by the way (although that could be possible too), it means a bunch of machines competing: `, + }, + { type: 'url', url: 'https://leaderboard.sbstats.uk/' }, + ]) +}) diff --git a/nip27.ts b/nip27.ts index 1a65490..ed07825 100644 --- a/nip27.ts +++ b/nip27.ts @@ -41,7 +41,7 @@ export type Block = } const noCharacter = /\W/m -const noURLCharacter = /\W |\W$|$|,| /m +const noURLCharacter = /[^\w\/] |[^\w\/]$|$|,| /m const MAX_HASHTAG_LENGTH = 42 export function* parse(content: string | NostrEvent): Iterable { diff --git a/package.json b/package.json index 6837541..3ba3ab1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "name": "nostr-tools", - "version": "2.19.3", + "version": "2.19.4", "description": "Tools for making a Nostr client.", "repository": { "type": "git",