nip27: fix trailing / in urls.

This commit is contained in:
fiatjaf
2025-12-11 21:23:32 -03:00
parent e290f98a86
commit 0235b490fa
4 changed files with 20 additions and 5 deletions

View File

@@ -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/' },
])
})