mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-12 18:08:52 +00:00
nip27: fix trailing / in urls.
This commit is contained in:
2
jsr.json
2
jsr.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nostr/tools",
|
"name": "@nostr/tools",
|
||||||
"version": "2.19.3",
|
"version": "2.19.4",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./index.ts",
|
".": "./index.ts",
|
||||||
"./core": "./core.ts",
|
"./core": "./core.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', () => {
|
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
|
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!`
|
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))
|
const blocks = Array.from(parse(content))
|
||||||
|
|
||||||
expect(blocks).toEqual([
|
expect(blocks).toEqual([
|
||||||
{ type: 'text', text: ':' },
|
{ 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: 'text', text: "; this was a relay and now here's a video -> " },
|
||||||
{ type: 'video', url: 'https://videos.com/video.mp4' },
|
{ type: 'video', url: 'https://videos.com/video.mp4' },
|
||||||
{ type: 'text', text: '! and some music:\n' },
|
{ 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:' }])
|
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/' },
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|||||||
2
nip27.ts
2
nip27.ts
@@ -41,7 +41,7 @@ export type Block =
|
|||||||
}
|
}
|
||||||
|
|
||||||
const noCharacter = /\W/m
|
const noCharacter = /\W/m
|
||||||
const noURLCharacter = /\W |\W$|$|,| /m
|
const noURLCharacter = /[^\w\/] |[^\w\/]$|$|,| /m
|
||||||
const MAX_HASHTAG_LENGTH = 42
|
const MAX_HASHTAG_LENGTH = 42
|
||||||
|
|
||||||
export function* parse(content: string | NostrEvent): Iterable<Block> {
|
export function* parse(content: string | NostrEvent): Iterable<Block> {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "nostr-tools",
|
"name": "nostr-tools",
|
||||||
"version": "2.19.3",
|
"version": "2.19.4",
|
||||||
"description": "Tools for making a Nostr client.",
|
"description": "Tools for making a Nostr client.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user