fast-uri 3.0.6 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +53 -5
- package/.github/workflows/lock-threads.yml +19 -0
- package/.github/workflows/package-manager-ci.yml +6 -2
- package/LICENSE +1 -1
- package/README.md +48 -28
- package/benchmark/benchmark.mjs +159 -0
- package/benchmark/equal.mjs +51 -0
- package/benchmark/non-simple-domain.mjs +22 -0
- package/benchmark/package.json +17 -0
- package/benchmark/string-array-to-hex-stripped.mjs +24 -0
- package/benchmark/ws-is-secure.mjs +65 -0
- package/index.js +100 -65
- package/lib/schemes.js +160 -81
- package/lib/utils.js +304 -126
- package/package.json +8 -8
- package/test/ajv.test.js +7 -3
- package/test/equal.test.js +7 -2
- package/test/fixtures/uri-js-parse.json +501 -0
- package/test/fixtures/uri-js-serialize.json +120 -0
- package/test/parse.test.js +31 -31
- package/test/resolve.test.js +52 -49
- package/test/rfc-3986.test.js +90 -0
- package/test/security-normalization.test.js +39 -0
- package/test/serialize.test.js +55 -47
- package/test/uri-js-compatibility.test.js +33 -0
- package/test/uri-js.test.js +230 -230
- package/test/util.test.js +23 -8
- package/tsconfig.json +9 -0
- package/types/index.d.ts +7 -0
- package/.github/.stale.yml +0 -21
- package/.github/tests_checker.yml +0 -8
- package/benchmark.js +0 -105
- package/lib/scopedChars.js +0 -30
- package/test/.gitkeep +0 -0
- package/test/compatibility.test.js +0 -131
package/test/serialize.test.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const test = require('tape')
|
|
4
|
-
const
|
|
4
|
+
const fastURI = require('..')
|
|
5
5
|
|
|
6
6
|
test('URI Serialize', (t) => {
|
|
7
7
|
let components = {
|
|
@@ -13,7 +13,7 @@ test('URI Serialize', (t) => {
|
|
|
13
13
|
query: undefined,
|
|
14
14
|
fragment: undefined
|
|
15
15
|
}
|
|
16
|
-
t.equal(
|
|
16
|
+
t.equal(fastURI.serialize(components), '', 'Undefined Components')
|
|
17
17
|
|
|
18
18
|
components = {
|
|
19
19
|
scheme: '',
|
|
@@ -24,7 +24,7 @@ test('URI Serialize', (t) => {
|
|
|
24
24
|
query: '',
|
|
25
25
|
fragment: ''
|
|
26
26
|
}
|
|
27
|
-
t.equal(
|
|
27
|
+
t.equal(fastURI.serialize(components), '//@:0?#', 'Empty Components')
|
|
28
28
|
|
|
29
29
|
components = {
|
|
30
30
|
scheme: 'uri',
|
|
@@ -35,97 +35,105 @@ test('URI Serialize', (t) => {
|
|
|
35
35
|
query: 'query',
|
|
36
36
|
fragment: 'fragment'
|
|
37
37
|
}
|
|
38
|
-
t.equal(
|
|
38
|
+
t.equal(fastURI.serialize(components), 'uri://foo:bar@example.com:1/path?query#fragment', 'All Components')
|
|
39
39
|
|
|
40
40
|
components = {
|
|
41
41
|
scheme: 'uri',
|
|
42
42
|
host: 'example.com',
|
|
43
43
|
port: '9000'
|
|
44
44
|
}
|
|
45
|
-
t.equal(
|
|
45
|
+
t.equal(fastURI.serialize(components), 'uri://example.com:9000', 'String port')
|
|
46
46
|
|
|
47
|
-
t.equal(
|
|
48
|
-
t.equal(
|
|
49
|
-
t.equal(
|
|
47
|
+
t.equal(fastURI.serialize({ path: '//path' }), '/%2Fpath', 'Double slash path')
|
|
48
|
+
t.equal(fastURI.serialize({ path: 'foo:bar' }), 'foo%3Abar', 'Colon path')
|
|
49
|
+
t.equal(fastURI.serialize({ path: '?query' }), '%3Fquery', 'Query path')
|
|
50
50
|
|
|
51
|
-
t.equal(
|
|
51
|
+
t.equal(fastURI.serialize({ host: '10.10.10.10' }), '//10.10.10.10', 'IPv4address')
|
|
52
52
|
|
|
53
53
|
// mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4)
|
|
54
|
-
t.equal(
|
|
54
|
+
t.equal(fastURI.serialize({ host: '10.10.10.10.example.com' }), '//10.10.10.10.example.com', 'Mixed IPv4address & reg-name')
|
|
55
55
|
|
|
56
56
|
// IPv6address
|
|
57
|
-
t.equal(
|
|
58
|
-
t.equal(
|
|
59
|
-
t.equal(
|
|
57
|
+
t.equal(fastURI.serialize({ host: '2001:db8::7' }), '//[2001:db8::7]', 'IPv6 Host')
|
|
58
|
+
t.equal(fastURI.serialize({ host: '::ffff:129.144.52.38' }), '//[::ffff:129.144.52.38]', 'IPv6 Mixed Host')
|
|
59
|
+
t.equal(fastURI.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' }), '//[2606:2800:220:1:248:1893:25c8:1946]', 'IPv6 Full Host')
|
|
60
60
|
|
|
61
61
|
// IPv6address with zone identifier, RFC 6874
|
|
62
|
-
t.equal(
|
|
63
|
-
t.equal(
|
|
62
|
+
t.equal(fastURI.serialize({ host: 'fe80::a%en1' }), '//[fe80::a%25en1]', 'IPv6 Zone Unescaped Host')
|
|
63
|
+
t.equal(fastURI.serialize({ host: 'fe80::a%25en1' }), '//[fe80::a%25en1]', 'IPv6 Zone Escaped Host')
|
|
64
64
|
|
|
65
65
|
t.end()
|
|
66
66
|
})
|
|
67
67
|
|
|
68
68
|
test('WS serialize', (t) => {
|
|
69
|
-
t.equal(
|
|
70
|
-
t.equal(
|
|
71
|
-
t.equal(
|
|
72
|
-
t.equal(
|
|
73
|
-
t.equal(
|
|
74
|
-
t.equal(
|
|
75
|
-
t.equal(
|
|
76
|
-
t.equal(
|
|
77
|
-
t.equal(
|
|
78
|
-
t.equal(
|
|
79
|
-
t.equal(
|
|
80
|
-
t.equal(
|
|
81
|
-
t.equal(
|
|
69
|
+
t.equal(fastURI.serialize({ scheme: 'ws' }), 'ws:')
|
|
70
|
+
t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com' }), 'ws://example.com')
|
|
71
|
+
t.equal(fastURI.serialize({ scheme: 'ws', resourceName: '/' }), 'ws:')
|
|
72
|
+
t.equal(fastURI.serialize({ scheme: 'ws', resourceName: '/foo' }), 'ws:/foo')
|
|
73
|
+
t.equal(fastURI.serialize({ scheme: 'ws', resourceName: '/foo?bar' }), 'ws:/foo?bar')
|
|
74
|
+
t.equal(fastURI.serialize({ scheme: 'ws', secure: false }), 'ws:')
|
|
75
|
+
t.equal(fastURI.serialize({ scheme: 'ws', secure: true }), 'wss:')
|
|
76
|
+
t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo' }), 'ws://example.com/foo')
|
|
77
|
+
t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar' }), 'ws://example.com/foo?bar')
|
|
78
|
+
t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', secure: false }), 'ws://example.com')
|
|
79
|
+
t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', secure: true }), 'wss://example.com')
|
|
80
|
+
t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: false }), 'ws://example.com/foo?bar')
|
|
81
|
+
t.equal(fastURI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true }), 'wss://example.com/foo?bar')
|
|
82
82
|
t.end()
|
|
83
83
|
})
|
|
84
84
|
|
|
85
85
|
test('WSS serialize', (t) => {
|
|
86
|
-
t.equal(
|
|
87
|
-
t.equal(
|
|
88
|
-
t.equal(
|
|
89
|
-
t.equal(
|
|
90
|
-
t.equal(
|
|
91
|
-
t.equal(
|
|
92
|
-
t.equal(
|
|
93
|
-
t.equal(
|
|
94
|
-
t.equal(
|
|
95
|
-
t.equal(
|
|
96
|
-
t.equal(
|
|
97
|
-
t.equal(
|
|
98
|
-
t.equal(
|
|
86
|
+
t.equal(fastURI.serialize({ scheme: 'wss' }), 'wss:')
|
|
87
|
+
t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com' }), 'wss://example.com')
|
|
88
|
+
t.equal(fastURI.serialize({ scheme: 'wss', resourceName: '/' }), 'wss:')
|
|
89
|
+
t.equal(fastURI.serialize({ scheme: 'wss', resourceName: '/foo' }), 'wss:/foo')
|
|
90
|
+
t.equal(fastURI.serialize({ scheme: 'wss', resourceName: '/foo?bar' }), 'wss:/foo?bar')
|
|
91
|
+
t.equal(fastURI.serialize({ scheme: 'wss', secure: false }), 'ws:')
|
|
92
|
+
t.equal(fastURI.serialize({ scheme: 'wss', secure: true }), 'wss:')
|
|
93
|
+
t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo' }), 'wss://example.com/foo')
|
|
94
|
+
t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar' }), 'wss://example.com/foo?bar')
|
|
95
|
+
t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', secure: false }), 'ws://example.com')
|
|
96
|
+
t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', secure: true }), 'wss://example.com')
|
|
97
|
+
t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar', secure: false }), 'ws://example.com/foo?bar')
|
|
98
|
+
t.equal(fastURI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar', secure: true }), 'wss://example.com/foo?bar')
|
|
99
99
|
|
|
100
100
|
t.end()
|
|
101
101
|
})
|
|
102
102
|
|
|
103
103
|
test('URN serialize', (t) => {
|
|
104
|
-
// example from RFC 2141
|
|
104
|
+
// example from RFC 2141
|
|
105
105
|
const components = {
|
|
106
106
|
scheme: 'urn',
|
|
107
107
|
nid: 'foo',
|
|
108
108
|
nss: 'a123,456'
|
|
109
109
|
}
|
|
110
|
-
t.equal(
|
|
110
|
+
t.equal(fastURI.serialize(components), 'urn:foo:a123,456')
|
|
111
111
|
// example from RFC 4122
|
|
112
112
|
let uuidcomponents = {
|
|
113
113
|
scheme: 'urn',
|
|
114
114
|
nid: 'uuid',
|
|
115
115
|
uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
|
|
116
116
|
}
|
|
117
|
-
t.equal(
|
|
117
|
+
t.equal(fastURI.serialize(uuidcomponents), 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')
|
|
118
118
|
|
|
119
119
|
uuidcomponents = {
|
|
120
120
|
scheme: 'urn',
|
|
121
121
|
nid: 'uuid',
|
|
122
122
|
uuid: 'notauuid-7dec-11d0-a765-00a0c91e6bf6'
|
|
123
123
|
}
|
|
124
|
-
t.equal(
|
|
124
|
+
t.equal(fastURI.serialize(uuidcomponents), 'urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6')
|
|
125
|
+
|
|
126
|
+
uuidcomponents = {
|
|
127
|
+
scheme: 'urn',
|
|
128
|
+
nid: undefined,
|
|
129
|
+
uuid: 'notauuid-7dec-11d0-a765-00a0c91e6bf6'
|
|
130
|
+
}
|
|
131
|
+
t.throws(() => { fastURI.serialize(uuidcomponents) }, 'URN without nid cannot be serialized')
|
|
132
|
+
|
|
125
133
|
t.end()
|
|
126
134
|
})
|
|
127
135
|
test('URN NID Override', (t) => {
|
|
128
|
-
let components =
|
|
136
|
+
let components = fastURI.parse('urn:foo:f81d4fae-7dec-11d0-a765-00a0c91e6bf6', { nid: 'uuid' })
|
|
129
137
|
t.equal(components.error, undefined, 'errors')
|
|
130
138
|
t.equal(components.scheme, 'urn', 'scheme')
|
|
131
139
|
t.equal(components.path, undefined, 'path')
|
|
@@ -138,6 +146,6 @@ test('URN NID Override', (t) => {
|
|
|
138
146
|
nid: 'foo',
|
|
139
147
|
uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
|
|
140
148
|
}
|
|
141
|
-
t.equal(
|
|
149
|
+
t.equal(fastURI.serialize(components, { nid: 'uuid' }), 'urn:foo:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')
|
|
142
150
|
t.end()
|
|
143
151
|
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const test = require('tape')
|
|
4
|
+
const fastURI = require('../')
|
|
5
|
+
|
|
6
|
+
const uriJsParseFixtures = require('./fixtures/uri-js-parse.json')
|
|
7
|
+
const uriJsSerializeFixtures = require('./fixtures/uri-js-serialize.json')
|
|
8
|
+
|
|
9
|
+
test('uri-js compatibility Parse', (t) => {
|
|
10
|
+
uriJsParseFixtures.forEach((
|
|
11
|
+
[value, expected]
|
|
12
|
+
) => {
|
|
13
|
+
if (value === '//10.10.000.10') {
|
|
14
|
+
return t.skip('Skipping //10.10.000.10 as it is not a valid URI per URI spec: https://datatracker.ietf.org/doc/html/rfc5954#section-4.1')
|
|
15
|
+
}
|
|
16
|
+
if (value.slice(0, 6) === 'mailto') {
|
|
17
|
+
return t.skip('Skipping mailto schema test as it is not supported by fastifyURI')
|
|
18
|
+
}
|
|
19
|
+
t.same(JSON.parse(JSON.stringify(fastURI.parse(value))), expected, 'Compatibility parse: ' + value)
|
|
20
|
+
})
|
|
21
|
+
t.end()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('uri-js compatibility serialize', (t) => {
|
|
25
|
+
uriJsSerializeFixtures.forEach(([value, expected]) => {
|
|
26
|
+
t.same(
|
|
27
|
+
fastURI.serialize(value),
|
|
28
|
+
expected,
|
|
29
|
+
'Compatibility serialize: ' + JSON.stringify(value)
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
t.end()
|
|
33
|
+
})
|