fast-uri 0.0.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.
@@ -0,0 +1,310 @@
1
+ 'use strict'
2
+
3
+ const tap = require('tap')
4
+ const test = tap.test
5
+ const URI = require('../')
6
+
7
+ test('URI parse', (t) => {
8
+ let components
9
+
10
+ // scheme
11
+ components = URI.parse('uri:')
12
+ t.equal(components.error, undefined, 'scheme errors')
13
+ t.equal(components.scheme, 'uri', 'scheme')
14
+ // t.equal(components.authority, undefined, "authority");
15
+ t.equal(components.userinfo, undefined, 'userinfo')
16
+ t.equal(components.host, undefined, 'host')
17
+ t.equal(components.port, undefined, 'port')
18
+ t.equal(components.path, '', 'path')
19
+ t.equal(components.query, undefined, 'query')
20
+ t.equal(components.fragment, undefined, 'fragment')
21
+
22
+ // userinfo
23
+ components = URI.parse('//@')
24
+ t.equal(components.error, undefined, 'userinfo errors')
25
+ t.equal(components.scheme, undefined, 'scheme')
26
+ // t.equal(components.authority, "@", "authority");
27
+ t.equal(components.userinfo, '', 'userinfo')
28
+ t.equal(components.host, '', 'host')
29
+ t.equal(components.port, undefined, 'port')
30
+ t.equal(components.path, '', 'path')
31
+ t.equal(components.query, undefined, 'query')
32
+ t.equal(components.fragment, undefined, 'fragment')
33
+
34
+ // host
35
+ components = URI.parse('//')
36
+ t.equal(components.error, undefined, 'host errors')
37
+ t.equal(components.scheme, undefined, 'scheme')
38
+ // t.equal(components.authority, "", "authority");
39
+ t.equal(components.userinfo, undefined, 'userinfo')
40
+ t.equal(components.host, '', 'host')
41
+ t.equal(components.port, undefined, 'port')
42
+ t.equal(components.path, '', 'path')
43
+ t.equal(components.query, undefined, 'query')
44
+ t.equal(components.fragment, undefined, 'fragment')
45
+
46
+ // port
47
+ components = URI.parse('//:')
48
+ t.equal(components.error, undefined, 'port errors')
49
+ t.equal(components.scheme, undefined, 'scheme')
50
+ // t.equal(components.authority, ":", "authority");
51
+ t.equal(components.userinfo, undefined, 'userinfo')
52
+ t.equal(components.host, '', 'host')
53
+ t.equal(components.port, '', 'port')
54
+ t.equal(components.path, '', 'path')
55
+ t.equal(components.query, undefined, 'query')
56
+ t.equal(components.fragment, undefined, 'fragment')
57
+
58
+ // path
59
+ components = URI.parse('')
60
+ t.equal(components.error, undefined, 'path errors')
61
+ t.equal(components.scheme, undefined, 'scheme')
62
+ // t.equal(components.authority, undefined, "authority");
63
+ t.equal(components.userinfo, undefined, 'userinfo')
64
+ t.equal(components.host, undefined, 'host')
65
+ t.equal(components.port, undefined, 'port')
66
+ t.equal(components.path, '', 'path')
67
+ t.equal(components.query, undefined, 'query')
68
+ t.equal(components.fragment, undefined, 'fragment')
69
+
70
+ // query
71
+ components = URI.parse('?')
72
+ t.equal(components.error, undefined, 'query errors')
73
+ t.equal(components.scheme, undefined, 'scheme')
74
+ // t.equal(components.authority, undefined, "authority");
75
+ t.equal(components.userinfo, undefined, 'userinfo')
76
+ t.equal(components.host, undefined, 'host')
77
+ t.equal(components.port, undefined, 'port')
78
+ t.equal(components.path, '', 'path')
79
+ t.equal(components.query, '', 'query')
80
+ t.equal(components.fragment, undefined, 'fragment')
81
+
82
+ // fragment
83
+ components = URI.parse('#')
84
+ t.equal(components.error, undefined, 'fragment errors')
85
+ t.equal(components.scheme, undefined, 'scheme')
86
+ // t.equal(components.authority, undefined, "authority");
87
+ t.equal(components.userinfo, undefined, 'userinfo')
88
+ t.equal(components.host, undefined, 'host')
89
+ t.equal(components.port, undefined, 'port')
90
+ t.equal(components.path, '', 'path')
91
+ t.equal(components.query, undefined, 'query')
92
+ t.equal(components.fragment, '', 'fragment')
93
+
94
+ // fragment with character tabulation
95
+ components = URI.parse('#\t')
96
+ t.equal(components.error, undefined, 'path errors')
97
+ t.equal(components.scheme, undefined, 'scheme')
98
+ // t.equal(components.authority, undefined, "authority");
99
+ t.equal(components.userinfo, undefined, 'userinfo')
100
+ t.equal(components.host, undefined, 'host')
101
+ t.equal(components.port, undefined, 'port')
102
+ t.equal(components.path, '', 'path')
103
+ t.equal(components.query, undefined, 'query')
104
+ t.equal(components.fragment, '%09', 'fragment')
105
+
106
+ // fragment with line feed
107
+ components = URI.parse('#\n')
108
+ t.equal(components.error, undefined, 'path errors')
109
+ t.equal(components.scheme, undefined, 'scheme')
110
+ // t.equal(components.authority, undefined, "authority");
111
+ t.equal(components.userinfo, undefined, 'userinfo')
112
+ t.equal(components.host, undefined, 'host')
113
+ t.equal(components.port, undefined, 'port')
114
+ t.equal(components.path, '', 'path')
115
+ t.equal(components.query, undefined, 'query')
116
+ t.equal(components.fragment, '%0A', 'fragment')
117
+
118
+ // fragment with line tabulation
119
+ components = URI.parse('#\v')
120
+ t.equal(components.error, undefined, 'path errors')
121
+ t.equal(components.scheme, undefined, 'scheme')
122
+ // t.equal(components.authority, undefined, "authority");
123
+ t.equal(components.userinfo, undefined, 'userinfo')
124
+ t.equal(components.host, undefined, 'host')
125
+ t.equal(components.port, undefined, 'port')
126
+ t.equal(components.path, '', 'path')
127
+ t.equal(components.query, undefined, 'query')
128
+ t.equal(components.fragment, '%0B', 'fragment')
129
+
130
+ // fragment with form feed
131
+ components = URI.parse('#\f')
132
+ t.equal(components.error, undefined, 'path errors')
133
+ t.equal(components.scheme, undefined, 'scheme')
134
+ // t.equal(components.authority, undefined, "authority");
135
+ t.equal(components.userinfo, undefined, 'userinfo')
136
+ t.equal(components.host, undefined, 'host')
137
+ t.equal(components.port, undefined, 'port')
138
+ t.equal(components.path, '', 'path')
139
+ t.equal(components.query, undefined, 'query')
140
+ t.equal(components.fragment, '%0C', 'fragment')
141
+
142
+ // fragment with carriage return
143
+ components = URI.parse('#\r')
144
+ t.equal(components.error, undefined, 'path errors')
145
+ t.equal(components.scheme, undefined, 'scheme')
146
+ // t.equal(components.authority, undefined, "authority");
147
+ t.equal(components.userinfo, undefined, 'userinfo')
148
+ t.equal(components.host, undefined, 'host')
149
+ t.equal(components.port, undefined, 'port')
150
+ t.equal(components.path, '', 'path')
151
+ t.equal(components.query, undefined, 'query')
152
+ t.equal(components.fragment, '%0D', 'fragment')
153
+
154
+ // all
155
+ components = URI.parse('uri://user:pass@example.com:123/one/two.three?q1=a1&q2=a2#body')
156
+ t.equal(components.error, undefined, 'all errors')
157
+ t.equal(components.scheme, 'uri', 'scheme')
158
+ // t.equal(components.authority, "user:pass@example.com:123", "authority");
159
+ t.equal(components.userinfo, 'user:pass', 'userinfo')
160
+ t.equal(components.host, 'example.com', 'host')
161
+ t.equal(components.port, 123, 'port')
162
+ t.equal(components.path, '/one/two.three', 'path')
163
+ t.equal(components.query, 'q1=a1&q2=a2', 'query')
164
+ t.equal(components.fragment, 'body', 'fragment')
165
+
166
+ // IPv4address
167
+ components = URI.parse('//10.10.10.10')
168
+ t.equal(components.error, undefined, 'IPv4address errors')
169
+ t.equal(components.scheme, undefined, 'scheme')
170
+ t.equal(components.userinfo, undefined, 'userinfo')
171
+ t.equal(components.host, '10.10.10.10', 'host')
172
+ t.equal(components.port, undefined, 'port')
173
+ t.equal(components.path, '', 'path')
174
+ t.equal(components.query, undefined, 'query')
175
+ t.equal(components.fragment, undefined, 'fragment')
176
+
177
+ // IPv4address with unformated 0
178
+ components = URI.parse('//10.10.000.10')
179
+ t.equal(components.error, undefined, 'IPv4address errors')
180
+ t.equal(components.scheme, undefined, 'scheme')
181
+ t.equal(components.userinfo, undefined, 'userinfo')
182
+ t.equal(components.host, '10.10.0.10', 'host')
183
+ t.equal(components.port, undefined, 'port')
184
+ t.equal(components.path, '', 'path')
185
+ t.equal(components.query, undefined, 'query')
186
+ t.equal(components.fragment, undefined, 'fragment')
187
+
188
+ // IPv6address
189
+ components = URI.parse('//[2001:db8::7]')
190
+ t.equal(components.error, undefined, 'IPv4address errors')
191
+ t.equal(components.scheme, undefined, 'scheme')
192
+ t.equal(components.userinfo, undefined, 'userinfo')
193
+ t.equal(components.host, '2001:db8::7', 'host')
194
+ t.equal(components.port, undefined, 'port')
195
+ t.equal(components.path, '', 'path')
196
+ t.equal(components.query, undefined, 'query')
197
+ t.equal(components.fragment, undefined, 'fragment')
198
+
199
+ // invalid IPv6
200
+ components = URI.parse('//[2001:dbZ::7]')
201
+ t.equal(components.host, '[2001:dbz::7]')
202
+
203
+ // mixed IPv4address & IPv6address
204
+ components = URI.parse('//[::ffff:129.144.52.38]')
205
+ t.equal(components.error, undefined, 'IPv4address errors')
206
+ t.equal(components.scheme, undefined, 'scheme')
207
+ t.equal(components.userinfo, undefined, 'userinfo')
208
+ t.equal(components.host, '::ffff:129.144.52.38', 'host')
209
+ t.equal(components.port, undefined, 'port')
210
+ t.equal(components.path, '', 'path')
211
+ t.equal(components.query, undefined, 'query')
212
+ t.equal(components.fragment, undefined, 'fragment')
213
+
214
+ // mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4)
215
+ components = URI.parse('uri://10.10.10.10.example.com/en/process')
216
+ t.equal(components.error, undefined, 'mixed errors')
217
+ t.equal(components.scheme, 'uri', 'scheme')
218
+ t.equal(components.userinfo, undefined, 'userinfo')
219
+ t.equal(components.host, '10.10.10.10.example.com', 'host')
220
+ t.equal(components.port, undefined, 'port')
221
+ t.equal(components.path, '/en/process', 'path')
222
+ t.equal(components.query, undefined, 'query')
223
+ t.equal(components.fragment, undefined, 'fragment')
224
+
225
+ // IPv6address, example from bkw (https://github.com/garycourt/uri-js/pull/16)
226
+ components = URI.parse('//[2606:2800:220:1:248:1893:25c8:1946]/test')
227
+ t.equal(components.error, undefined, 'IPv6address errors')
228
+ t.equal(components.scheme, undefined, 'scheme')
229
+ t.equal(components.userinfo, undefined, 'userinfo')
230
+ t.equal(components.host, '2606:2800:220:1:248:1893:25c8:1946', 'host')
231
+ t.equal(components.port, undefined, 'port')
232
+ t.equal(components.path, '/test', 'path')
233
+ t.equal(components.query, undefined, 'query')
234
+ t.equal(components.fragment, undefined, 'fragment')
235
+
236
+ // IPv6address, example from RFC 5952
237
+ components = URI.parse('//[2001:db8::1]:80')
238
+ t.equal(components.error, undefined, 'IPv6address errors')
239
+ t.equal(components.scheme, undefined, 'scheme')
240
+ t.equal(components.userinfo, undefined, 'userinfo')
241
+ t.equal(components.host, '2001:db8::1', 'host')
242
+ t.equal(components.port, 80, 'port')
243
+ t.equal(components.path, '', 'path')
244
+ t.equal(components.query, undefined, 'query')
245
+ t.equal(components.fragment, undefined, 'fragment')
246
+
247
+ // IPv6address with zone identifier, RFC 6874
248
+ components = URI.parse('//[fe80::a%25en1]')
249
+ t.equal(components.error, undefined, 'IPv4address errors')
250
+ t.equal(components.scheme, undefined, 'scheme')
251
+ t.equal(components.userinfo, undefined, 'userinfo')
252
+ t.equal(components.host, 'fe80::a%en1', 'host')
253
+ t.equal(components.port, undefined, 'port')
254
+ t.equal(components.path, '', 'path')
255
+ t.equal(components.query, undefined, 'query')
256
+ t.equal(components.fragment, undefined, 'fragment')
257
+
258
+ // IPv6address with an unescaped interface specifier, example from pekkanikander (https://github.com/garycourt/uri-js/pull/22)
259
+ components = URI.parse('//[2001:db8::7%en0]')
260
+ t.equal(components.error, undefined, 'IPv6address interface errors')
261
+ t.equal(components.scheme, undefined, 'scheme')
262
+ t.equal(components.userinfo, undefined, 'userinfo')
263
+ t.equal(components.host, '2001:db8::7%en0', 'host')
264
+ t.equal(components.port, undefined, 'port')
265
+ t.equal(components.path, '', 'path')
266
+ t.equal(components.query, undefined, 'query')
267
+ t.equal(components.fragment, undefined, 'fragment')
268
+
269
+ // UUID V1
270
+ components = URI.parse('urn:uuid:b571b0bc-4713-11ec-81d3-0242ac130003')
271
+ t.equal(components.error, undefined, 'errors')
272
+ t.equal(components.scheme, 'urn', 'scheme')
273
+ // t.equal(components.authority, undefined, "authority");
274
+ t.equal(components.userinfo, undefined, 'userinfo')
275
+ t.equal(components.host, undefined, 'host')
276
+ t.equal(components.port, undefined, 'port')
277
+ t.equal(components.path, undefined, 'path')
278
+ t.equal(components.query, undefined, 'query')
279
+ t.equal(components.fragment, undefined, 'fragment')
280
+ t.equal(components.nid, 'uuid', 'nid')
281
+ t.equal(components.nss, undefined, 'nss')
282
+ t.equal(components.uuid, 'b571b0bc-4713-11ec-81d3-0242ac130003', 'uuid')
283
+
284
+ // UUID v4
285
+ components = URI.parse('urn:uuid:97a32222-89b7-420e-8507-4360723e2c2a')
286
+ t.equal(components.uuid, '97a32222-89b7-420e-8507-4360723e2c2a', 'uuid')
287
+
288
+ components = URI.parse('urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6')
289
+ t.notSame(components.error, undefined, 'errors')
290
+
291
+ components = URI.parse('urn:foo:a123,456')
292
+ t.equal(components.error, undefined, 'errors')
293
+ t.equal(components.scheme, 'urn', 'scheme')
294
+ // t.equal(components.authority, undefined, "authority");
295
+ t.equal(components.userinfo, undefined, 'userinfo')
296
+ t.equal(components.host, undefined, 'host')
297
+ t.equal(components.port, undefined, 'port')
298
+ t.equal(components.path, undefined, 'path')
299
+ t.equal(components.query, undefined, 'query')
300
+ t.equal(components.fragment, undefined, 'fragment')
301
+ t.equal(components.nid, 'foo', 'nid')
302
+ t.equal(components.nss, 'a123,456', 'nss')
303
+
304
+ components = URI.parse('//[2606:2800:220:1:248:1893:25c8:1946:43209]')
305
+ t.equal(components.host, '[2606:2800:220:1:248:1893:25c8:1946:43209]')
306
+
307
+ components = URI.parse('urn:foo:|\\24fpl')
308
+ t.equal(components.error, 'URN can not be parsed.')
309
+ t.end()
310
+ })
@@ -0,0 +1,76 @@
1
+ 'use strict'
2
+
3
+ const tap = require('tap')
4
+ const test = tap.test
5
+ const URI = require('../')
6
+
7
+ test('URI Resolving', (t) => {
8
+ // normal examples from RFC 3986
9
+ const base = 'uri://a/b/c/d;p?q'
10
+ t.equal(URI.resolve(base, 'g:h'), 'g:h', 'g:h')
11
+ t.equal(URI.resolve(base, 'g:h'), 'g:h', 'g:h')
12
+ t.equal(URI.resolve(base, 'g'), 'uri://a/b/c/g', 'g')
13
+ t.equal(URI.resolve(base, './g'), 'uri://a/b/c/g', './g')
14
+ t.equal(URI.resolve(base, 'g/'), 'uri://a/b/c/g/', 'g/')
15
+ t.equal(URI.resolve(base, '/g'), 'uri://a/g', '/g')
16
+ t.equal(URI.resolve(base, '//g'), 'uri://g', '//g')
17
+ t.equal(URI.resolve(base, '?y'), 'uri://a/b/c/d;p?y', '?y')
18
+ t.equal(URI.resolve(base, 'g?y'), 'uri://a/b/c/g?y', 'g?y')
19
+ t.equal(URI.resolve(base, '#s'), 'uri://a/b/c/d;p?q#s', '#s')
20
+ t.equal(URI.resolve(base, 'g#s'), 'uri://a/b/c/g#s', 'g#s')
21
+ t.equal(URI.resolve(base, 'g?y#s'), 'uri://a/b/c/g?y#s', 'g?y#s')
22
+ t.equal(URI.resolve(base, ';x'), 'uri://a/b/c/;x', ';x')
23
+ t.equal(URI.resolve(base, 'g;x'), 'uri://a/b/c/g;x', 'g;x')
24
+ t.equal(URI.resolve(base, 'g;x?y#s'), 'uri://a/b/c/g;x?y#s', 'g;x?y#s')
25
+ t.equal(URI.resolve(base, ''), 'uri://a/b/c/d;p?q', '')
26
+ t.equal(URI.resolve(base, '.'), 'uri://a/b/c/', '.')
27
+ t.equal(URI.resolve(base, './'), 'uri://a/b/c/', './')
28
+ t.equal(URI.resolve(base, '..'), 'uri://a/b/', '..')
29
+ t.equal(URI.resolve(base, '../'), 'uri://a/b/', '../')
30
+ t.equal(URI.resolve(base, '../g'), 'uri://a/b/g', '../g')
31
+ t.equal(URI.resolve(base, '../..'), 'uri://a/', '../..')
32
+ t.equal(URI.resolve(base, '../../'), 'uri://a/', '../../')
33
+ t.equal(URI.resolve(base, '../../g'), 'uri://a/g', '../../g')
34
+
35
+ // abnormal examples from RFC 3986
36
+ t.equal(URI.resolve(base, '../../../g'), 'uri://a/g', '../../../g')
37
+ t.equal(URI.resolve(base, '../../../../g'), 'uri://a/g', '../../../../g')
38
+
39
+ t.equal(URI.resolve(base, '/./g'), 'uri://a/g', '/./g')
40
+ t.equal(URI.resolve(base, '/../g'), 'uri://a/g', '/../g')
41
+ t.equal(URI.resolve(base, 'g.'), 'uri://a/b/c/g.', 'g.')
42
+ t.equal(URI.resolve(base, '.g'), 'uri://a/b/c/.g', '.g')
43
+ t.equal(URI.resolve(base, 'g..'), 'uri://a/b/c/g..', 'g..')
44
+ t.equal(URI.resolve(base, '..g'), 'uri://a/b/c/..g', '..g')
45
+
46
+ t.equal(URI.resolve(base, './../g'), 'uri://a/b/g', './../g')
47
+ t.equal(URI.resolve(base, './g/.'), 'uri://a/b/c/g/', './g/.')
48
+ t.equal(URI.resolve(base, 'g/./h'), 'uri://a/b/c/g/h', 'g/./h')
49
+ t.equal(URI.resolve(base, 'g/../h'), 'uri://a/b/c/h', 'g/../h')
50
+ t.equal(URI.resolve(base, 'g;x=1/./y'), 'uri://a/b/c/g;x=1/y', 'g;x=1/./y')
51
+ t.equal(URI.resolve(base, 'g;x=1/../y'), 'uri://a/b/c/y', 'g;x=1/../y')
52
+
53
+ t.equal(URI.resolve(base, 'g?y/./x'), 'uri://a/b/c/g?y/./x', 'g?y/./x')
54
+ t.equal(URI.resolve(base, 'g?y/../x'), 'uri://a/b/c/g?y/../x', 'g?y/../x')
55
+ t.equal(URI.resolve(base, 'g#s/./x'), 'uri://a/b/c/g#s/./x', 'g#s/./x')
56
+ t.equal(URI.resolve(base, 'g#s/../x'), 'uri://a/b/c/g#s/../x', 'g#s/../x')
57
+
58
+ t.equal(URI.resolve(base, 'uri:g'), 'uri:g', 'uri:g')
59
+ t.equal(URI.resolve(base, 'uri:g', { tolerant: true }), 'uri://a/b/c/g', 'uri:g')
60
+
61
+ // examples by PAEz
62
+ // example was provided to avoid infinite loop within regex
63
+ // this is not the case anymore
64
+ // t.equal(URI.resolve('//www.g.com/', '/adf\ngf'), '//www.g.com/adf%0Agf', '/adf\\ngf')
65
+ // t.equal(URI.resolve('//www.g.com/error\n/bleh/bleh', '..'), '//www.g.com/error%0A/', '//www.g.com/error\\n/bleh/bleh')
66
+ t.end()
67
+ })
68
+
69
+ test('URN Resolving', (t) => {
70
+ // example from epoberezkin
71
+ t.equal(URI.resolve('', 'urn:some:ip:prop'), 'urn:some:ip:prop', 'urn:some:ip:prop')
72
+ t.equal(URI.resolve('#', 'urn:some:ip:prop'), 'urn:some:ip:prop', 'urn:some:ip:prop')
73
+ t.equal(URI.resolve('urn:some:ip:prop', 'urn:some:ip:prop'), 'urn:some:ip:prop', 'urn:some:ip:prop')
74
+ t.equal(URI.resolve('urn:some:other:prop', 'urn:some:ip:prop'), 'urn:some:ip:prop', 'urn:some:ip:prop')
75
+ t.end()
76
+ })
@@ -0,0 +1,144 @@
1
+ 'use strict'
2
+
3
+ const tap = require('tap')
4
+ const test = tap.test
5
+ const URI = require('../')
6
+
7
+ test('URI Serialize', (t) => {
8
+ let components = {
9
+ scheme: undefined,
10
+ userinfo: undefined,
11
+ host: undefined,
12
+ port: undefined,
13
+ path: undefined,
14
+ query: undefined,
15
+ fragment: undefined
16
+ }
17
+ t.equal(URI.serialize(components), '', 'Undefined Components')
18
+
19
+ components = {
20
+ scheme: '',
21
+ userinfo: '',
22
+ host: '',
23
+ port: 0,
24
+ path: '',
25
+ query: '',
26
+ fragment: ''
27
+ }
28
+ t.equal(URI.serialize(components), '//@:0?#', 'Empty Components')
29
+
30
+ components = {
31
+ scheme: 'uri',
32
+ userinfo: 'foo:bar',
33
+ host: 'example.com',
34
+ port: 1,
35
+ path: 'path',
36
+ query: 'query',
37
+ fragment: 'fragment'
38
+ }
39
+ t.equal(URI.serialize(components), 'uri://foo:bar@example.com:1/path?query#fragment', 'All Components')
40
+
41
+ components = {
42
+ scheme: 'uri',
43
+ host: 'example.com',
44
+ port: '9000'
45
+ }
46
+ t.equal(URI.serialize(components), 'uri://example.com:9000', 'String port')
47
+
48
+ t.equal(URI.serialize({ path: '//path' }), '/%2Fpath', 'Double slash path')
49
+ t.equal(URI.serialize({ path: 'foo:bar' }), 'foo%3Abar', 'Colon path')
50
+ t.equal(URI.serialize({ path: '?query' }), '%3Fquery', 'Query path')
51
+
52
+ t.equal(URI.serialize({ host: '10.10.10.10' }), '//10.10.10.10', 'IPv4address')
53
+
54
+ // mixed IPv4address & reg-name, example from terion-name (https://github.com/garycourt/uri-js/issues/4)
55
+ t.equal(URI.serialize({ host: '10.10.10.10.example.com' }), '//10.10.10.10.example.com', 'Mixed IPv4address & reg-name')
56
+
57
+ // IPv6address
58
+ t.equal(URI.serialize({ host: '2001:db8::7' }), '//[2001:db8::7]', 'IPv6 Host')
59
+ t.equal(URI.serialize({ host: '::ffff:129.144.52.38' }), '//[::ffff:129.144.52.38]', 'IPv6 Mixed Host')
60
+ t.equal(URI.serialize({ host: '2606:2800:220:1:248:1893:25c8:1946' }), '//[2606:2800:220:1:248:1893:25c8:1946]', 'IPv6 Full Host')
61
+
62
+ // IPv6address with zone identifier, RFC 6874
63
+ t.equal(URI.serialize({ host: 'fe80::a%en1' }), '//[fe80::a%25en1]', 'IPv6 Zone Unescaped Host')
64
+ t.equal(URI.serialize({ host: 'fe80::a%25en1' }), '//[fe80::a%25en1]', 'IPv6 Zone Escaped Host')
65
+
66
+ t.end()
67
+ })
68
+
69
+ test('WS serialize', (t) => {
70
+ t.equal(URI.serialize({ scheme: 'ws' }), 'ws:')
71
+ t.equal(URI.serialize({ scheme: 'ws', host: 'example.com' }), 'ws://example.com')
72
+ t.equal(URI.serialize({ scheme: 'ws', resourceName: '/' }), 'ws:')
73
+ t.equal(URI.serialize({ scheme: 'ws', resourceName: '/foo' }), 'ws:/foo')
74
+ t.equal(URI.serialize({ scheme: 'ws', resourceName: '/foo?bar' }), 'ws:/foo?bar')
75
+ t.equal(URI.serialize({ scheme: 'ws', secure: false }), 'ws:')
76
+ t.equal(URI.serialize({ scheme: 'ws', secure: true }), 'wss:')
77
+ t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo' }), 'ws://example.com/foo')
78
+ t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar' }), 'ws://example.com/foo?bar')
79
+ t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', secure: false }), 'ws://example.com')
80
+ t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', secure: true }), 'wss://example.com')
81
+ t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: false }), 'ws://example.com/foo?bar')
82
+ t.equal(URI.serialize({ scheme: 'ws', host: 'example.com', resourceName: '/foo?bar', secure: true }), 'wss://example.com/foo?bar')
83
+ t.end()
84
+ })
85
+
86
+ test('WSS serialize', (t) => {
87
+ t.equal(URI.serialize({ scheme: 'wss' }), 'wss:')
88
+ t.equal(URI.serialize({ scheme: 'wss', host: 'example.com' }), 'wss://example.com')
89
+ t.equal(URI.serialize({ scheme: 'wss', resourceName: '/' }), 'wss:')
90
+ t.equal(URI.serialize({ scheme: 'wss', resourceName: '/foo' }), 'wss:/foo')
91
+ t.equal(URI.serialize({ scheme: 'wss', resourceName: '/foo?bar' }), 'wss:/foo?bar')
92
+ t.equal(URI.serialize({ scheme: 'wss', secure: false }), 'ws:')
93
+ t.equal(URI.serialize({ scheme: 'wss', secure: true }), 'wss:')
94
+ t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo' }), 'wss://example.com/foo')
95
+ t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar' }), 'wss://example.com/foo?bar')
96
+ t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', secure: false }), 'ws://example.com')
97
+ t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', secure: true }), 'wss://example.com')
98
+ t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar', secure: false }), 'ws://example.com/foo?bar')
99
+ t.equal(URI.serialize({ scheme: 'wss', host: 'example.com', resourceName: '/foo?bar', secure: true }), 'wss://example.com/foo?bar')
100
+
101
+ t.end()
102
+ })
103
+
104
+ test('URN serialize', (t) => {
105
+ // example from RFC 2141
106
+ const components = {
107
+ scheme: 'urn',
108
+ nid: 'foo',
109
+ nss: 'a123,456'
110
+ }
111
+ t.equal(URI.serialize(components), 'urn:foo:a123,456')
112
+ // example from RFC 4122
113
+ let uuidcomponents = {
114
+ scheme: 'urn',
115
+ nid: 'uuid',
116
+ uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
117
+ }
118
+ t.equal(URI.serialize(uuidcomponents), 'urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')
119
+
120
+ uuidcomponents = {
121
+ scheme: 'urn',
122
+ nid: 'uuid',
123
+ uuid: 'notauuid-7dec-11d0-a765-00a0c91e6bf6'
124
+ }
125
+ t.equal(URI.serialize(uuidcomponents), 'urn:uuid:notauuid-7dec-11d0-a765-00a0c91e6bf6')
126
+ t.end()
127
+ })
128
+ test('URN NID Override', (t) => {
129
+ let components = URI.parse('urn:foo:f81d4fae-7dec-11d0-a765-00a0c91e6bf6', { nid: 'uuid' })
130
+ t.equal(components.error, undefined, 'errors')
131
+ t.equal(components.scheme, 'urn', 'scheme')
132
+ t.equal(components.path, undefined, 'path')
133
+ t.equal(components.nid, 'foo', 'nid')
134
+ t.equal(components.nss, undefined, 'nss')
135
+ t.equal(components.uuid, 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6', 'uuid')
136
+
137
+ components = {
138
+ scheme: 'urn',
139
+ nid: 'foo',
140
+ uuid: 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6'
141
+ }
142
+ t.equal(URI.serialize(components, { nid: 'uuid' }), 'urn:foo:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')
143
+ t.end()
144
+ })
package/types/.gitkeep ADDED
File without changes