source: trip-planner-front/node_modules/url/test.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 46.1 KB
Line 
1// Copyright Joyent, Inc. and other Node contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to permit
8// persons to whom the Software is furnished to do so, subject to the
9// following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22var assert = require('assert');
23
24var url = require('./url');
25
26// URLs to parse, and expected data
27// { url : parsed }
28var parseTests = {
29 '//some_path' : {
30 'href': '//some_path',
31 'pathname': '//some_path',
32 'path': '//some_path'
33 },
34
35 'http:\\\\evil-phisher\\foo.html#h\\a\\s\\h': {
36 protocol: 'http:',
37 slashes: true,
38 host: 'evil-phisher',
39 hostname: 'evil-phisher',
40 pathname: '/foo.html',
41 path: '/foo.html',
42 hash: '#h%5Ca%5Cs%5Ch',
43 href: 'http://evil-phisher/foo.html#h%5Ca%5Cs%5Ch'
44 },
45
46 'http:\\\\evil-phisher\\foo.html?json="\\"foo\\""#h\\a\\s\\h': {
47 protocol: 'http:',
48 slashes: true,
49 host: 'evil-phisher',
50 hostname: 'evil-phisher',
51 pathname: '/foo.html',
52 search: '?json=%22%5C%22foo%5C%22%22',
53 query: 'json=%22%5C%22foo%5C%22%22',
54 path: '/foo.html?json=%22%5C%22foo%5C%22%22',
55 hash: '#h%5Ca%5Cs%5Ch',
56 href: 'http://evil-phisher/foo.html?json=%22%5C%22foo%5C%22%22#h%5Ca%5Cs%5Ch'
57 },
58
59 'http:\\\\evil-phisher\\foo.html#h\\a\\s\\h?blarg': {
60 protocol: 'http:',
61 slashes: true,
62 host: 'evil-phisher',
63 hostname: 'evil-phisher',
64 pathname: '/foo.html',
65 path: '/foo.html',
66 hash: '#h%5Ca%5Cs%5Ch?blarg',
67 href: 'http://evil-phisher/foo.html#h%5Ca%5Cs%5Ch?blarg'
68 },
69
70
71 'http:\\\\evil-phisher\\foo.html': {
72 protocol: 'http:',
73 slashes: true,
74 host: 'evil-phisher',
75 hostname: 'evil-phisher',
76 pathname: '/foo.html',
77 path: '/foo.html',
78 href: 'http://evil-phisher/foo.html'
79 },
80
81 'HTTP://www.example.com/' : {
82 'href': 'http://www.example.com/',
83 'protocol': 'http:',
84 'slashes': true,
85 'host': 'www.example.com',
86 'hostname': 'www.example.com',
87 'pathname': '/',
88 'path': '/'
89 },
90
91 'HTTP://www.example.com' : {
92 'href': 'http://www.example.com/',
93 'protocol': 'http:',
94 'slashes': true,
95 'host': 'www.example.com',
96 'hostname': 'www.example.com',
97 'pathname': '/',
98 'path': '/'
99 },
100
101 'http://www.ExAmPlE.com/' : {
102 'href': 'http://www.example.com/',
103 'protocol': 'http:',
104 'slashes': true,
105 'host': 'www.example.com',
106 'hostname': 'www.example.com',
107 'pathname': '/',
108 'path': '/'
109 },
110
111 'http://user:pw@www.ExAmPlE.com/' : {
112 'href': 'http://user:pw@www.example.com/',
113 'protocol': 'http:',
114 'slashes': true,
115 'auth': 'user:pw',
116 'host': 'www.example.com',
117 'hostname': 'www.example.com',
118 'pathname': '/',
119 'path': '/'
120 },
121
122 'http://USER:PW@www.ExAmPlE.com/' : {
123 'href': 'http://USER:PW@www.example.com/',
124 'protocol': 'http:',
125 'slashes': true,
126 'auth': 'USER:PW',
127 'host': 'www.example.com',
128 'hostname': 'www.example.com',
129 'pathname': '/',
130 'path': '/'
131 },
132
133 'http://user@www.example.com/' : {
134 'href': 'http://user@www.example.com/',
135 'protocol': 'http:',
136 'slashes': true,
137 'auth': 'user',
138 'host': 'www.example.com',
139 'hostname': 'www.example.com',
140 'pathname': '/',
141 'path': '/'
142 },
143
144 'http://user%3Apw@www.example.com/' : {
145 'href': 'http://user:pw@www.example.com/',
146 'protocol': 'http:',
147 'slashes': true,
148 'auth': 'user:pw',
149 'host': 'www.example.com',
150 'hostname': 'www.example.com',
151 'pathname': '/',
152 'path': '/'
153 },
154
155 'http://x.com/path?that\'s#all, folks' : {
156 'href': 'http://x.com/path?that%27s#all,%20folks',
157 'protocol': 'http:',
158 'slashes': true,
159 'host': 'x.com',
160 'hostname': 'x.com',
161 'search': '?that%27s',
162 'query': 'that%27s',
163 'pathname': '/path',
164 'hash': '#all,%20folks',
165 'path': '/path?that%27s'
166 },
167
168 'HTTP://X.COM/Y' : {
169 'href': 'http://x.com/Y',
170 'protocol': 'http:',
171 'slashes': true,
172 'host': 'x.com',
173 'hostname': 'x.com',
174 'pathname': '/Y',
175 'path': '/Y'
176 },
177
178 // + not an invalid host character
179 // per https://url.spec.whatwg.org/#host-parsing
180 'http://x.y.com+a/b/c' : {
181 'href': 'http://x.y.com+a/b/c',
182 'protocol': 'http:',
183 'slashes': true,
184 'host': 'x.y.com+a',
185 'hostname': 'x.y.com+a',
186 'pathname': '/b/c',
187 'path': '/b/c'
188 },
189
190 // an unexpected invalid char in the hostname.
191 'HtTp://x.y.cOm;a/b/c?d=e#f g<h>i' : {
192 'href': 'http://x.y.com/;a/b/c?d=e#f%20g%3Ch%3Ei',
193 'protocol': 'http:',
194 'slashes': true,
195 'host': 'x.y.com',
196 'hostname': 'x.y.com',
197 'pathname': ';a/b/c',
198 'search': '?d=e',
199 'query': 'd=e',
200 'hash': '#f%20g%3Ch%3Ei',
201 'path': ';a/b/c?d=e'
202 },
203
204 // make sure that we don't accidentally lcast the path parts.
205 'HtTp://x.y.cOm;A/b/c?d=e#f g<h>i' : {
206 'href': 'http://x.y.com/;A/b/c?d=e#f%20g%3Ch%3Ei',
207 'protocol': 'http:',
208 'slashes': true,
209 'host': 'x.y.com',
210 'hostname': 'x.y.com',
211 'pathname': ';A/b/c',
212 'search': '?d=e',
213 'query': 'd=e',
214 'hash': '#f%20g%3Ch%3Ei',
215 'path': ';A/b/c?d=e'
216 },
217
218 'http://x...y...#p': {
219 'href': 'http://x...y.../#p',
220 'protocol': 'http:',
221 'slashes': true,
222 'host': 'x...y...',
223 'hostname': 'x...y...',
224 'hash': '#p',
225 'pathname': '/',
226 'path': '/'
227 },
228
229 'http://x/p/"quoted"': {
230 'href': 'http://x/p/%22quoted%22',
231 'protocol': 'http:',
232 'slashes': true,
233 'host': 'x',
234 'hostname': 'x',
235 'pathname': '/p/%22quoted%22',
236 'path': '/p/%22quoted%22'
237 },
238
239 '<http://goo.corn/bread> Is a URL!': {
240 'href': '%3Chttp://goo.corn/bread%3E%20Is%20a%20URL!',
241 'pathname': '%3Chttp://goo.corn/bread%3E%20Is%20a%20URL!',
242 'path': '%3Chttp://goo.corn/bread%3E%20Is%20a%20URL!'
243 },
244
245 'http://www.narwhaljs.org/blog/categories?id=news' : {
246 'href': 'http://www.narwhaljs.org/blog/categories?id=news',
247 'protocol': 'http:',
248 'slashes': true,
249 'host': 'www.narwhaljs.org',
250 'hostname': 'www.narwhaljs.org',
251 'search': '?id=news',
252 'query': 'id=news',
253 'pathname': '/blog/categories',
254 'path': '/blog/categories?id=news'
255 },
256
257 'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=' : {
258 'href': 'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=',
259 'protocol': 'http:',
260 'slashes': true,
261 'host': 'mt0.google.com',
262 'hostname': 'mt0.google.com',
263 'pathname': '/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=',
264 'path': '/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s='
265 },
266
267 'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' : {
268 'href': 'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api' +
269 '&x=2&y=2&z=3&s=',
270 'protocol': 'http:',
271 'slashes': true,
272 'host': 'mt0.google.com',
273 'hostname': 'mt0.google.com',
274 'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',
275 'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',
276 'pathname': '/vt/lyrs=m@114',
277 'path': '/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s='
278 },
279
280 'http://user:pass@mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=':
281 {
282 'href': 'http://user:pass@mt0.google.com/vt/lyrs=m@114???' +
283 '&hl=en&src=api&x=2&y=2&z=3&s=',
284 'protocol': 'http:',
285 'slashes': true,
286 'host': 'mt0.google.com',
287 'auth': 'user:pass',
288 'hostname': 'mt0.google.com',
289 'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',
290 'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',
291 'pathname': '/vt/lyrs=m@114',
292 'path': '/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s='
293 },
294
295 'file:///etc/passwd' : {
296 'href': 'file:///etc/passwd',
297 'slashes': true,
298 'protocol': 'file:',
299 'pathname': '/etc/passwd',
300 'hostname': '',
301 'host': '',
302 'path': '/etc/passwd'
303 },
304
305 'file://localhost/etc/passwd' : {
306 'href': 'file://localhost/etc/passwd',
307 'protocol': 'file:',
308 'slashes': true,
309 'pathname': '/etc/passwd',
310 'hostname': 'localhost',
311 'host': 'localhost',
312 'path': '/etc/passwd'
313 },
314
315 'file://foo/etc/passwd' : {
316 'href': 'file://foo/etc/passwd',
317 'protocol': 'file:',
318 'slashes': true,
319 'pathname': '/etc/passwd',
320 'hostname': 'foo',
321 'host': 'foo',
322 'path': '/etc/passwd'
323 },
324
325 'file:///etc/node/' : {
326 'href': 'file:///etc/node/',
327 'slashes': true,
328 'protocol': 'file:',
329 'pathname': '/etc/node/',
330 'hostname': '',
331 'host': '',
332 'path': '/etc/node/'
333 },
334
335 'file://localhost/etc/node/' : {
336 'href': 'file://localhost/etc/node/',
337 'protocol': 'file:',
338 'slashes': true,
339 'pathname': '/etc/node/',
340 'hostname': 'localhost',
341 'host': 'localhost',
342 'path': '/etc/node/'
343 },
344
345 'file://foo/etc/node/' : {
346 'href': 'file://foo/etc/node/',
347 'protocol': 'file:',
348 'slashes': true,
349 'pathname': '/etc/node/',
350 'hostname': 'foo',
351 'host': 'foo',
352 'path': '/etc/node/'
353 },
354
355 'http:/baz/../foo/bar' : {
356 'href': 'http:/baz/../foo/bar',
357 'protocol': 'http:',
358 'pathname': '/baz/../foo/bar',
359 'path': '/baz/../foo/bar'
360 },
361
362 'http://user:pass@example.com:8000/foo/bar?baz=quux#frag' : {
363 'href': 'http://user:pass@example.com:8000/foo/bar?baz=quux#frag',
364 'protocol': 'http:',
365 'slashes': true,
366 'host': 'example.com:8000',
367 'auth': 'user:pass',
368 'port': '8000',
369 'hostname': 'example.com',
370 'hash': '#frag',
371 'search': '?baz=quux',
372 'query': 'baz=quux',
373 'pathname': '/foo/bar',
374 'path': '/foo/bar?baz=quux'
375 },
376
377 '//user:pass@example.com:8000/foo/bar?baz=quux#frag' : {
378 'href': '//user:pass@example.com:8000/foo/bar?baz=quux#frag',
379 'slashes': true,
380 'host': 'example.com:8000',
381 'auth': 'user:pass',
382 'port': '8000',
383 'hostname': 'example.com',
384 'hash': '#frag',
385 'search': '?baz=quux',
386 'query': 'baz=quux',
387 'pathname': '/foo/bar',
388 'path': '/foo/bar?baz=quux'
389 },
390
391 '/foo/bar?baz=quux#frag' : {
392 'href': '/foo/bar?baz=quux#frag',
393 'hash': '#frag',
394 'search': '?baz=quux',
395 'query': 'baz=quux',
396 'pathname': '/foo/bar',
397 'path': '/foo/bar?baz=quux'
398 },
399
400 'http:/foo/bar?baz=quux#frag' : {
401 'href': 'http:/foo/bar?baz=quux#frag',
402 'protocol': 'http:',
403 'hash': '#frag',
404 'search': '?baz=quux',
405 'query': 'baz=quux',
406 'pathname': '/foo/bar',
407 'path': '/foo/bar?baz=quux'
408 },
409
410 'mailto:foo@bar.com?subject=hello' : {
411 'href': 'mailto:foo@bar.com?subject=hello',
412 'protocol': 'mailto:',
413 'host': 'bar.com',
414 'auth' : 'foo',
415 'hostname' : 'bar.com',
416 'search': '?subject=hello',
417 'query': 'subject=hello',
418 'path': '?subject=hello'
419 },
420
421 'javascript:alert(\'hello\');' : {
422 'href': 'javascript:alert(\'hello\');',
423 'protocol': 'javascript:',
424 'pathname': 'alert(\'hello\');',
425 'path': 'alert(\'hello\');'
426 },
427
428 'xmpp:isaacschlueter@jabber.org' : {
429 'href': 'xmpp:isaacschlueter@jabber.org',
430 'protocol': 'xmpp:',
431 'host': 'jabber.org',
432 'auth': 'isaacschlueter',
433 'hostname': 'jabber.org'
434 },
435
436 'http://atpass:foo%40bar@127.0.0.1:8080/path?search=foo#bar' : {
437 'href' : 'http://atpass:foo%40bar@127.0.0.1:8080/path?search=foo#bar',
438 'protocol' : 'http:',
439 'slashes': true,
440 'host' : '127.0.0.1:8080',
441 'auth' : 'atpass:foo@bar',
442 'hostname' : '127.0.0.1',
443 'port' : '8080',
444 'pathname': '/path',
445 'search' : '?search=foo',
446 'query' : 'search=foo',
447 'hash' : '#bar',
448 'path': '/path?search=foo'
449 },
450
451 'svn+ssh://foo/bar': {
452 'href': 'svn+ssh://foo/bar',
453 'host': 'foo',
454 'hostname': 'foo',
455 'protocol': 'svn+ssh:',
456 'pathname': '/bar',
457 'path': '/bar',
458 'slashes': true
459 },
460
461 'dash-test://foo/bar': {
462 'href': 'dash-test://foo/bar',
463 'host': 'foo',
464 'hostname': 'foo',
465 'protocol': 'dash-test:',
466 'pathname': '/bar',
467 'path': '/bar',
468 'slashes': true
469 },
470
471 'dash-test:foo/bar': {
472 'href': 'dash-test:foo/bar',
473 'host': 'foo',
474 'hostname': 'foo',
475 'protocol': 'dash-test:',
476 'pathname': '/bar',
477 'path': '/bar'
478 },
479
480 'dot.test://foo/bar': {
481 'href': 'dot.test://foo/bar',
482 'host': 'foo',
483 'hostname': 'foo',
484 'protocol': 'dot.test:',
485 'pathname': '/bar',
486 'path': '/bar',
487 'slashes': true
488 },
489
490 'dot.test:foo/bar': {
491 'href': 'dot.test:foo/bar',
492 'host': 'foo',
493 'hostname': 'foo',
494 'protocol': 'dot.test:',
495 'pathname': '/bar',
496 'path': '/bar'
497 },
498
499 // IDNA tests
500 'http://www.日本語.com/' : {
501 'href': 'http://www.xn--wgv71a119e.com/',
502 'protocol': 'http:',
503 'slashes': true,
504 'host': 'www.xn--wgv71a119e.com',
505 'hostname': 'www.xn--wgv71a119e.com',
506 'pathname': '/',
507 'path': '/'
508 },
509
510 'http://example.Bücher.com/' : {
511 'href': 'http://example.xn--bcher-kva.com/',
512 'protocol': 'http:',
513 'slashes': true,
514 'host': 'example.xn--bcher-kva.com',
515 'hostname': 'example.xn--bcher-kva.com',
516 'pathname': '/',
517 'path': '/'
518 },
519
520 'http://www.Äffchen.com/' : {
521 'href': 'http://www.xn--ffchen-9ta.com/',
522 'protocol': 'http:',
523 'slashes': true,
524 'host': 'www.xn--ffchen-9ta.com',
525 'hostname': 'www.xn--ffchen-9ta.com',
526 'pathname': '/',
527 'path': '/'
528 },
529
530 'http://www.Äffchen.cOm;A/b/c?d=e#f g<h>i' : {
531 'href': 'http://www.xn--ffchen-9ta.com/;A/b/c?d=e#f%20g%3Ch%3Ei',
532 'protocol': 'http:',
533 'slashes': true,
534 'host': 'www.xn--ffchen-9ta.com',
535 'hostname': 'www.xn--ffchen-9ta.com',
536 'pathname': ';A/b/c',
537 'search': '?d=e',
538 'query': 'd=e',
539 'hash': '#f%20g%3Ch%3Ei',
540 'path': ';A/b/c?d=e'
541 },
542
543 'http://SÉLIER.COM/' : {
544 'href': 'http://xn--slier-bsa.com/',
545 'protocol': 'http:',
546 'slashes': true,
547 'host': 'xn--slier-bsa.com',
548 'hostname': 'xn--slier-bsa.com',
549 'pathname': '/',
550 'path': '/'
551 },
552
553 'http://ليهمابتكلموشعربي؟.ي؟/' : {
554 'href': 'http://xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f/',
555 'protocol': 'http:',
556 'slashes': true,
557 'host': 'xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f',
558 'hostname': 'xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f',
559 'pathname': '/',
560 'path': '/'
561 },
562
563 'http://➡.ws/➡' : {
564 'href': 'http://xn--hgi.ws/➡',
565 'protocol': 'http:',
566 'slashes': true,
567 'host': 'xn--hgi.ws',
568 'hostname': 'xn--hgi.ws',
569 'pathname': '/➡',
570 'path': '/➡'
571 },
572
573 'http://bucket_name.s3.amazonaws.com/image.jpg': {
574 protocol: 'http:',
575 'slashes': true,
576 slashes: true,
577 host: 'bucket_name.s3.amazonaws.com',
578 hostname: 'bucket_name.s3.amazonaws.com',
579 pathname: '/image.jpg',
580 href: 'http://bucket_name.s3.amazonaws.com/image.jpg',
581 'path': '/image.jpg'
582 },
583
584 'git+http://github.com/joyent/node.git': {
585 protocol: 'git+http:',
586 slashes: true,
587 host: 'github.com',
588 hostname: 'github.com',
589 pathname: '/joyent/node.git',
590 path: '/joyent/node.git',
591 href: 'git+http://github.com/joyent/node.git'
592 },
593
594 //if local1@domain1 is uses as a relative URL it may
595 //be parse into auth@hostname, but here there is no
596 //way to make it work in url.parse, I add the test to be explicit
597 'local1@domain1': {
598 'pathname': 'local1@domain1',
599 'path': 'local1@domain1',
600 'href': 'local1@domain1'
601 },
602
603 //While this may seem counter-intuitive, a browser will parse
604 //<a href='www.google.com'> as a path.
605 'www.example.com' : {
606 'href': 'www.example.com',
607 'pathname': 'www.example.com',
608 'path': 'www.example.com'
609 },
610
611 // ipv6 support
612 '[fe80::1]': {
613 'href': '[fe80::1]',
614 'pathname': '[fe80::1]',
615 'path': '[fe80::1]'
616 },
617
618 'coap://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]': {
619 'protocol': 'coap:',
620 'slashes': true,
621 'host': '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]',
622 'hostname': 'fedc:ba98:7654:3210:fedc:ba98:7654:3210',
623 'href': 'coap://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/',
624 'pathname': '/',
625 'path': '/'
626 },
627
628 'coap://[1080:0:0:0:8:800:200C:417A]:61616/': {
629 'protocol': 'coap:',
630 'slashes': true,
631 'host': '[1080:0:0:0:8:800:200c:417a]:61616',
632 'port': '61616',
633 'hostname': '1080:0:0:0:8:800:200c:417a',
634 'href': 'coap://[1080:0:0:0:8:800:200c:417a]:61616/',
635 'pathname': '/',
636 'path': '/'
637 },
638
639 'http://user:password@[3ffe:2a00:100:7031::1]:8080': {
640 'protocol': 'http:',
641 'slashes': true,
642 'auth': 'user:password',
643 'host': '[3ffe:2a00:100:7031::1]:8080',
644 'port': '8080',
645 'hostname': '3ffe:2a00:100:7031::1',
646 'href': 'http://user:password@[3ffe:2a00:100:7031::1]:8080/',
647 'pathname': '/',
648 'path': '/'
649 },
650
651 'coap://u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature': {
652 'protocol': 'coap:',
653 'slashes': true,
654 'auth': 'u:p',
655 'host': '[::192.9.5.5]:61616',
656 'port': '61616',
657 'hostname': '::192.9.5.5',
658 'href': 'coap://u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature',
659 'search': '?n=Temperature',
660 'query': 'n=Temperature',
661 'pathname': '/.well-known/r',
662 'path': '/.well-known/r?n=Temperature'
663 },
664
665 // empty port
666 'http://example.com:': {
667 'protocol': 'http:',
668 'slashes': true,
669 'host': 'example.com',
670 'hostname': 'example.com',
671 'href': 'http://example.com/',
672 'pathname': '/',
673 'path': '/'
674 },
675
676 'http://example.com:/a/b.html': {
677 'protocol': 'http:',
678 'slashes': true,
679 'host': 'example.com',
680 'hostname': 'example.com',
681 'href': 'http://example.com/a/b.html',
682 'pathname': '/a/b.html',
683 'path': '/a/b.html'
684 },
685
686 'http://example.com:?a=b': {
687 'protocol': 'http:',
688 'slashes': true,
689 'host': 'example.com',
690 'hostname': 'example.com',
691 'href': 'http://example.com/?a=b',
692 'search': '?a=b',
693 'query': 'a=b',
694 'pathname': '/',
695 'path': '/?a=b'
696 },
697
698 'http://example.com:#abc': {
699 'protocol': 'http:',
700 'slashes': true,
701 'host': 'example.com',
702 'hostname': 'example.com',
703 'href': 'http://example.com/#abc',
704 'hash': '#abc',
705 'pathname': '/',
706 'path': '/'
707 },
708
709 'http://[fe80::1]:/a/b?a=b#abc': {
710 'protocol': 'http:',
711 'slashes': true,
712 'host': '[fe80::1]',
713 'hostname': 'fe80::1',
714 'href': 'http://[fe80::1]/a/b?a=b#abc',
715 'search': '?a=b',
716 'query': 'a=b',
717 'hash': '#abc',
718 'pathname': '/a/b',
719 'path': '/a/b?a=b'
720 },
721
722 'http://-lovemonsterz.tumblr.com/rss': {
723 'protocol': 'http:',
724 'slashes': true,
725 'host': '-lovemonsterz.tumblr.com',
726 'hostname': '-lovemonsterz.tumblr.com',
727 'href': 'http://-lovemonsterz.tumblr.com/rss',
728 'pathname': '/rss',
729 'path': '/rss',
730 },
731
732 'http://-lovemonsterz.tumblr.com:80/rss': {
733 'protocol': 'http:',
734 'slashes': true,
735 'port': '80',
736 'host': '-lovemonsterz.tumblr.com:80',
737 'hostname': '-lovemonsterz.tumblr.com',
738 'href': 'http://-lovemonsterz.tumblr.com:80/rss',
739 'pathname': '/rss',
740 'path': '/rss',
741 },
742
743 'http://user:pass@-lovemonsterz.tumblr.com/rss': {
744 'protocol': 'http:',
745 'slashes': true,
746 'auth': 'user:pass',
747 'host': '-lovemonsterz.tumblr.com',
748 'hostname': '-lovemonsterz.tumblr.com',
749 'href': 'http://user:pass@-lovemonsterz.tumblr.com/rss',
750 'pathname': '/rss',
751 'path': '/rss',
752 },
753
754 'http://user:pass@-lovemonsterz.tumblr.com:80/rss': {
755 'protocol': 'http:',
756 'slashes': true,
757 'auth': 'user:pass',
758 'port': '80',
759 'host': '-lovemonsterz.tumblr.com:80',
760 'hostname': '-lovemonsterz.tumblr.com',
761 'href': 'http://user:pass@-lovemonsterz.tumblr.com:80/rss',
762 'pathname': '/rss',
763 'path': '/rss',
764 },
765
766 'http://_jabber._tcp.google.com/test': {
767 'protocol': 'http:',
768 'slashes': true,
769 'host': '_jabber._tcp.google.com',
770 'hostname': '_jabber._tcp.google.com',
771 'href': 'http://_jabber._tcp.google.com/test',
772 'pathname': '/test',
773 'path': '/test',
774 },
775
776 'http://user:pass@_jabber._tcp.google.com/test': {
777 'protocol': 'http:',
778 'slashes': true,
779 'auth': 'user:pass',
780 'host': '_jabber._tcp.google.com',
781 'hostname': '_jabber._tcp.google.com',
782 'href': 'http://user:pass@_jabber._tcp.google.com/test',
783 'pathname': '/test',
784 'path': '/test',
785 },
786
787 'http://_jabber._tcp.google.com:80/test': {
788 'protocol': 'http:',
789 'slashes': true,
790 'port': '80',
791 'host': '_jabber._tcp.google.com:80',
792 'hostname': '_jabber._tcp.google.com',
793 'href': 'http://_jabber._tcp.google.com:80/test',
794 'pathname': '/test',
795 'path': '/test',
796 },
797
798 'http://user:pass@_jabber._tcp.google.com:80/test': {
799 'protocol': 'http:',
800 'slashes': true,
801 'auth': 'user:pass',
802 'port': '80',
803 'host': '_jabber._tcp.google.com:80',
804 'hostname': '_jabber._tcp.google.com',
805 'href': 'http://user:pass@_jabber._tcp.google.com:80/test',
806 'pathname': '/test',
807 'path': '/test',
808 },
809
810 'http://x:1/\' <>"`/{}|\\^~`/': {
811 protocol: 'http:',
812 slashes: true,
813 host: 'x:1',
814 port: '1',
815 hostname: 'x',
816 pathname: '/%27%20%3C%3E%22%60/%7B%7D%7C/%5E~%60/',
817 path: '/%27%20%3C%3E%22%60/%7B%7D%7C/%5E~%60/',
818 href: 'http://x:1/%27%20%3C%3E%22%60/%7B%7D%7C/%5E~%60/'
819 },
820
821 'http://a@b@c/': {
822 protocol: 'http:',
823 slashes: true,
824 auth: 'a@b',
825 host: 'c',
826 hostname: 'c',
827 href: 'http://a%40b@c/',
828 path: '/',
829 pathname: '/'
830 },
831
832 'http://a@b?@c': {
833 protocol: 'http:',
834 slashes: true,
835 auth: 'a',
836 host: 'b',
837 hostname: 'b',
838 href: 'http://a@b/?@c',
839 path: '/?@c',
840 pathname: '/',
841 search: '?@c',
842 query: '@c'
843 },
844
845 'http://a\r" \t\n<\'b:b@c\r\nd/e?f':{
846 protocol: 'http:',
847 slashes: true,
848 auth: 'a\r" \t\n<\'b:b',
849 host: 'c',
850 port: null,
851 hostname: 'c',
852 hash: null,
853 search: '?f',
854 query: 'f',
855 pathname: '%0D%0Ad/e',
856 path: '%0D%0Ad/e?f',
857 href: 'http://a%0D%22%20%09%0A%3C\'b:b@c/%0D%0Ad/e?f'
858 },
859
860 // git urls used by npm
861 'git+ssh://git@github.com:npm/npm': {
862 protocol: 'git+ssh:',
863 slashes: true,
864 auth: 'git',
865 host: 'github.com',
866 port: null,
867 hostname: 'github.com',
868 hash: null,
869 search: null,
870 query: null,
871 pathname: '/:npm/npm',
872 path: '/:npm/npm',
873 href: 'git+ssh://git@github.com/:npm/npm'
874 }
875
876};
877
878Object.keys(parseTests).forEach(function(u) {
879 test('parse(' + u + ')', function() {
880 var actual = url.parse(u),
881 spaced = url.parse(' \t ' + u + '\n\t');
882 expected = parseTests[u];
883
884 Object.keys(actual).forEach(function (i) {
885 if (expected[i] === undefined && actual[i] === null) {
886 expected[i] = null;
887 }
888 });
889
890 assert.deepEqual(actual, expected);
891 assert.deepEqual(spaced, expected);
892
893 var expected = parseTests[u].href,
894 actual = url.format(parseTests[u]);
895
896 assert.equal(actual, expected,
897 'format(' + u + ') == ' + u + '\nactual:' + actual);
898 });
899});
900
901var parseTestsWithQueryString = {
902 '/foo/bar?baz=quux#frag' : {
903 'href': '/foo/bar?baz=quux#frag',
904 'hash': '#frag',
905 'search': '?baz=quux',
906 'query': {
907 'baz': 'quux'
908 },
909 'pathname': '/foo/bar',
910 'path': '/foo/bar?baz=quux'
911 },
912 'http://example.com' : {
913 'href': 'http://example.com/',
914 'protocol': 'http:',
915 'slashes': true,
916 'host': 'example.com',
917 'hostname': 'example.com',
918 'query': {},
919 'search': '',
920 'pathname': '/',
921 'path': '/'
922 },
923 '/example': {
924 protocol: null,
925 slashes: null,
926 auth: null,
927 host: null,
928 port: null,
929 hostname: null,
930 hash: null,
931 search: '',
932 query: {},
933 pathname: '/example',
934 path: '/example',
935 href: '/example'
936 },
937 '/example?query=value':{
938 protocol: null,
939 slashes: null,
940 auth: null,
941 host: null,
942 port: null,
943 hostname: null,
944 hash: null,
945 search: '?query=value',
946 query: { query: 'value' },
947 pathname: '/example',
948 path: '/example?query=value',
949 href: '/example?query=value'
950 }
951};
952
953Object.keys(parseTestsWithQueryString).forEach(function(u) {
954 test('parse(' + u + ')', function() {
955 var actual = url.parse(u, true);
956 var expected = parseTestsWithQueryString[u];
957 for (var i in actual) {
958 if (actual[i] === null && expected[i] === undefined) {
959 expected[i] = null;
960 }
961 }
962
963 assert.deepEqual(actual, expected);
964 });
965});
966
967// some extra formatting tests, just to verify
968// that it'll format slightly wonky content to a valid url.
969var formatTests = {
970 'http://example.com?' : {
971 'href': 'http://example.com/?',
972 'protocol': 'http:',
973 'slashes': true,
974 'host': 'example.com',
975 'hostname': 'example.com',
976 'search': '?',
977 'query': {},
978 'pathname': '/'
979 },
980 'http://example.com?foo=bar#frag' : {
981 'href': 'http://example.com/?foo=bar#frag',
982 'protocol': 'http:',
983 'host': 'example.com',
984 'hostname': 'example.com',
985 'hash': '#frag',
986 'search': '?foo=bar',
987 'query': 'foo=bar',
988 'pathname': '/'
989 },
990 'http://example.com?foo=@bar#frag' : {
991 'href': 'http://example.com/?foo=@bar#frag',
992 'protocol': 'http:',
993 'host': 'example.com',
994 'hostname': 'example.com',
995 'hash': '#frag',
996 'search': '?foo=@bar',
997 'query': 'foo=@bar',
998 'pathname': '/'
999 },
1000 'http://example.com?foo=/bar/#frag' : {
1001 'href': 'http://example.com/?foo=/bar/#frag',
1002 'protocol': 'http:',
1003 'host': 'example.com',
1004 'hostname': 'example.com',
1005 'hash': '#frag',
1006 'search': '?foo=/bar/',
1007 'query': 'foo=/bar/',
1008 'pathname': '/'
1009 },
1010 'http://example.com?foo=?bar/#frag' : {
1011 'href': 'http://example.com/?foo=?bar/#frag',
1012 'protocol': 'http:',
1013 'host': 'example.com',
1014 'hostname': 'example.com',
1015 'hash': '#frag',
1016 'search': '?foo=?bar/',
1017 'query': 'foo=?bar/',
1018 'pathname': '/'
1019 },
1020 'http://example.com#frag=?bar/#frag' : {
1021 'href': 'http://example.com/#frag=?bar/#frag',
1022 'protocol': 'http:',
1023 'host': 'example.com',
1024 'hostname': 'example.com',
1025 'hash': '#frag=?bar/#frag',
1026 'pathname': '/'
1027 },
1028 'http://google.com" onload="alert(42)/' : {
1029 'href': 'http://google.com/%22%20onload=%22alert(42)/',
1030 'protocol': 'http:',
1031 'host': 'google.com',
1032 'pathname': '/%22%20onload=%22alert(42)/'
1033 },
1034 'http://a.com/a/b/c?s#h' : {
1035 'href': 'http://a.com/a/b/c?s#h',
1036 'protocol': 'http',
1037 'host': 'a.com',
1038 'pathname': 'a/b/c',
1039 'hash': 'h',
1040 'search': 's'
1041 },
1042 'xmpp:isaacschlueter@jabber.org' : {
1043 'href': 'xmpp:isaacschlueter@jabber.org',
1044 'protocol': 'xmpp:',
1045 'host': 'jabber.org',
1046 'auth': 'isaacschlueter',
1047 'hostname': 'jabber.org'
1048 },
1049 'http://atpass:foo%40bar@127.0.0.1/' : {
1050 'href': 'http://atpass:foo%40bar@127.0.0.1/',
1051 'auth': 'atpass:foo@bar',
1052 'hostname': '127.0.0.1',
1053 'protocol': 'http:',
1054 'pathname': '/'
1055 },
1056 'http://atslash%2F%40:%2F%40@foo/' : {
1057 'href': 'http://atslash%2F%40:%2F%40@foo/',
1058 'auth': 'atslash/@:/@',
1059 'hostname': 'foo',
1060 'protocol': 'http:',
1061 'pathname': '/'
1062 },
1063 'svn+ssh://foo/bar': {
1064 'href': 'svn+ssh://foo/bar',
1065 'hostname': 'foo',
1066 'protocol': 'svn+ssh:',
1067 'pathname': '/bar',
1068 'slashes': true
1069 },
1070 'dash-test://foo/bar': {
1071 'href': 'dash-test://foo/bar',
1072 'hostname': 'foo',
1073 'protocol': 'dash-test:',
1074 'pathname': '/bar',
1075 'slashes': true
1076 },
1077 'dash-test:foo/bar': {
1078 'href': 'dash-test:foo/bar',
1079 'hostname': 'foo',
1080 'protocol': 'dash-test:',
1081 'pathname': '/bar'
1082 },
1083 'dot.test://foo/bar': {
1084 'href': 'dot.test://foo/bar',
1085 'hostname': 'foo',
1086 'protocol': 'dot.test:',
1087 'pathname': '/bar',
1088 'slashes': true
1089 },
1090 'dot.test:foo/bar': {
1091 'href': 'dot.test:foo/bar',
1092 'hostname': 'foo',
1093 'protocol': 'dot.test:',
1094 'pathname': '/bar'
1095 },
1096 // ipv6 support
1097 'coap:u:p@[::1]:61616/.well-known/r?n=Temperature': {
1098 'href': 'coap:u:p@[::1]:61616/.well-known/r?n=Temperature',
1099 'protocol': 'coap:',
1100 'auth': 'u:p',
1101 'hostname': '::1',
1102 'port': '61616',
1103 'pathname': '/.well-known/r',
1104 'search': 'n=Temperature'
1105 },
1106 'coap:[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616/s/stopButton': {
1107 'href': 'coap:[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616/s/stopButton',
1108 'protocol': 'coap',
1109 'host': '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616',
1110 'pathname': '/s/stopButton'
1111 },
1112
1113 // encode context-specific delimiters in path and query, but do not touch
1114 // other non-delimiter chars like `%`.
1115 // <https://github.com/joyent/node/issues/4082>
1116
1117 // `#`,`?` in path
1118 '/path/to/%%23%3F+=&.txt?foo=theA1#bar' : {
1119 href : '/path/to/%%23%3F+=&.txt?foo=theA1#bar',
1120 pathname: '/path/to/%#?+=&.txt',
1121 query: {
1122 foo: 'theA1'
1123 },
1124 hash: "#bar"
1125 },
1126
1127 // `#`,`?` in path + `#` in query
1128 '/path/to/%%23%3F+=&.txt?foo=the%231#bar' : {
1129 href : '/path/to/%%23%3F+=&.txt?foo=the%231#bar',
1130 pathname: '/path/to/%#?+=&.txt',
1131 query: {
1132 foo: 'the#1'
1133 },
1134 hash: "#bar"
1135 },
1136
1137 // `?` and `#` in path and search
1138 'http://ex.com/foo%3F100%m%23r?abc=the%231?&foo=bar#frag': {
1139 href: 'http://ex.com/foo%3F100%m%23r?abc=the%231?&foo=bar#frag',
1140 protocol: 'http:',
1141 hostname: 'ex.com',
1142 hash: '#frag',
1143 search: '?abc=the#1?&foo=bar',
1144 pathname: '/foo?100%m#r',
1145 },
1146
1147 // `?` and `#` in search only
1148 'http://ex.com/fooA100%mBr?abc=the%231?&foo=bar#frag': {
1149 href: 'http://ex.com/fooA100%mBr?abc=the%231?&foo=bar#frag',
1150 protocol: 'http:',
1151 hostname: 'ex.com',
1152 hash: '#frag',
1153 search: '?abc=the#1?&foo=bar',
1154 pathname: '/fooA100%mBr',
1155 }
1156};
1157
1158Object.keys(formatTests).forEach(function(u) {
1159 test('format(' + u + ')', function() {
1160 var expect = formatTests[u].href;
1161 delete formatTests[u].href;
1162 var actual = url.format(u);
1163 var actualObj = url.format(formatTests[u]);
1164 assert.equal(actual, expect,
1165 'wonky format(' + u + ') == ' + expect +
1166 '\nactual:' + actual);
1167 assert.equal(actualObj, expect,
1168 'wonky format(' + JSON.stringify(formatTests[u]) +
1169 ') == ' + expect +
1170 '\nactual: ' + actualObj);
1171 });
1172});
1173
1174/*
1175 [from, path, expected]
1176*/
1177var relativeTests = [
1178 ['/foo/bar/baz', 'quux', '/foo/bar/quux'],
1179 ['/foo/bar/baz', 'quux/asdf', '/foo/bar/quux/asdf'],
1180 ['/foo/bar/baz', 'quux/baz', '/foo/bar/quux/baz'],
1181 ['/foo/bar/baz', '../quux/baz', '/foo/quux/baz'],
1182 ['/foo/bar/baz', '/bar', '/bar'],
1183 ['/foo/bar/baz/', 'quux', '/foo/bar/baz/quux'],
1184 ['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],
1185 ['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'],
1186 ['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'],
1187 ['/foo', '.', '/'],
1188 ['/foo', '..', '/'],
1189 ['/foo/', '.', '/foo/'],
1190 ['/foo/', '..', '/'],
1191 ['/foo/bar', '.', '/foo/'],
1192 ['/foo/bar', '..', '/'],
1193 ['/foo/bar/', '.', '/foo/bar/'],
1194 ['/foo/bar/', '..', '/foo/'],
1195 ['foo/bar', '../../../baz', '../../baz'],
1196 ['foo/bar/', '../../../baz', '../baz'],
1197 ['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'],
1198 ['http://example.com/b//c//d;p?q#blarg',
1199 'https:/p/a/t/h?s#hash2',
1200 'https://p/a/t/h?s#hash2'],
1201 ['http://example.com/b//c//d;p?q#blarg',
1202 'https://u:p@h.com/p/a/t/h?s#hash2',
1203 'https://u:p@h.com/p/a/t/h?s#hash2'],
1204 ['http://example.com/b//c//d;p?q#blarg',
1205 'https:/a/b/c/d',
1206 'https://a/b/c/d'],
1207 ['http://example.com/b//c//d;p?q#blarg',
1208 'http:#hash2',
1209 'http://example.com/b//c//d;p?q#hash2'],
1210 ['http://example.com/b//c//d;p?q#blarg',
1211 'http:/p/a/t/h?s#hash2',
1212 'http://example.com/p/a/t/h?s#hash2'],
1213 ['http://example.com/b//c//d;p?q#blarg',
1214 'http://u:p@h.com/p/a/t/h?s#hash2',
1215 'http://u:p@h.com/p/a/t/h?s#hash2'],
1216 ['http://example.com/b//c//d;p?q#blarg',
1217 'http:/a/b/c/d',
1218 'http://example.com/a/b/c/d'],
1219 ['/foo/bar/baz', '/../etc/passwd', '/etc/passwd']
1220];
1221
1222relativeTests.forEach(function(relativeTest) {
1223 test('resolve(' + [relativeTest[0], relativeTest[1]] + ')', function() {
1224 var a = url.resolve(relativeTest[0], relativeTest[1]),
1225 e = relativeTest[2];
1226 assert.equal(a, e,
1227 'resolve(' + [relativeTest[0], relativeTest[1]] + ') == ' + e +
1228 '\n actual=' + a);
1229 });
1230});
1231
1232
1233// https://github.com/joyent/node/issues/568
1234[
1235 undefined,
1236 null,
1237 true,
1238 false,
1239 0.0,
1240 0,
1241 [],
1242 {}
1243].forEach(function(val) {
1244 test('parse(' + val + ')', function() {
1245 assert.throws(function() { url.parse(val); }, TypeError);
1246 });
1247});
1248
1249
1250//
1251// Tests below taken from Chiron
1252// http://code.google.com/p/chironjs/source/browse/trunk/src/test/http/url.js
1253//
1254// Copyright (c) 2002-2008 Kris Kowal <http://cixar.com/~kris.kowal>
1255// used with permission under MIT License
1256//
1257// Changes marked with @isaacs
1258
1259var bases = [
1260 'http://a/b/c/d;p?q',
1261 'http://a/b/c/d;p?q=1/2',
1262 'http://a/b/c/d;p=1/2?q',
1263 'fred:///s//a/b/c',
1264 'http:///s//a/b/c'
1265];
1266
1267//[to, from, result]
1268var relativeTests2 = [
1269 // http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html
1270 ['../c', 'foo:a/b', 'foo:c'],
1271 ['foo:.', 'foo:a', 'foo:'],
1272 ['/foo/../../../bar', 'zz:abc', 'zz:/bar'],
1273 ['/foo/../bar', 'zz:abc', 'zz:/bar'],
1274 // @isaacs Disagree. Not how web browsers resolve this.
1275 ['foo/../../../bar', 'zz:abc', 'zz:bar'],
1276 // ['foo/../../../bar', 'zz:abc', 'zz:../../bar'], // @isaacs Added
1277 ['foo/../bar', 'zz:abc', 'zz:bar'],
1278 ['zz:.', 'zz:abc', 'zz:'],
1279 ['/.', bases[0], 'http://a/'],
1280 ['/.foo', bases[0], 'http://a/.foo'],
1281 ['.foo', bases[0], 'http://a/b/c/.foo'],
1282
1283 // http://gbiv.com/protocols/uri/test/rel_examples1.html
1284 // examples from RFC 2396
1285 ['g:h', bases[0], 'g:h'],
1286 ['g', bases[0], 'http://a/b/c/g'],
1287 ['./g', bases[0], 'http://a/b/c/g'],
1288 ['g/', bases[0], 'http://a/b/c/g/'],
1289 ['/g', bases[0], 'http://a/g'],
1290 ['//g', bases[0], 'http://g/'],
1291 // changed with RFC 2396bis
1292 //('?y', bases[0], 'http://a/b/c/d;p?y'],
1293 ['?y', bases[0], 'http://a/b/c/d;p?y'],
1294 ['g?y', bases[0], 'http://a/b/c/g?y'],
1295 // changed with RFC 2396bis
1296 //('#s', bases[0], CURRENT_DOC_URI + '#s'],
1297 ['#s', bases[0], 'http://a/b/c/d;p?q#s'],
1298 ['g#s', bases[0], 'http://a/b/c/g#s'],
1299 ['g?y#s', bases[0], 'http://a/b/c/g?y#s'],
1300 [';x', bases[0], 'http://a/b/c/;x'],
1301 ['g;x', bases[0], 'http://a/b/c/g;x'],
1302 ['g;x?y#s' , bases[0], 'http://a/b/c/g;x?y#s'],
1303 // changed with RFC 2396bis
1304 //('', bases[0], CURRENT_DOC_URI],
1305 ['', bases[0], 'http://a/b/c/d;p?q'],
1306 ['.', bases[0], 'http://a/b/c/'],
1307 ['./', bases[0], 'http://a/b/c/'],
1308 ['..', bases[0], 'http://a/b/'],
1309 ['../', bases[0], 'http://a/b/'],
1310 ['../g', bases[0], 'http://a/b/g'],
1311 ['../..', bases[0], 'http://a/'],
1312 ['../../', bases[0], 'http://a/'],
1313 ['../../g' , bases[0], 'http://a/g'],
1314 ['../../../g', bases[0], ('http://a/../g', 'http://a/g')],
1315 ['../../../../g', bases[0], ('http://a/../../g', 'http://a/g')],
1316 // changed with RFC 2396bis
1317 //('/./g', bases[0], 'http://a/./g'],
1318 ['/./g', bases[0], 'http://a/g'],
1319 // changed with RFC 2396bis
1320 //('/../g', bases[0], 'http://a/../g'],
1321 ['/../g', bases[0], 'http://a/g'],
1322 ['g.', bases[0], 'http://a/b/c/g.'],
1323 ['.g', bases[0], 'http://a/b/c/.g'],
1324 ['g..', bases[0], 'http://a/b/c/g..'],
1325 ['..g', bases[0], 'http://a/b/c/..g'],
1326 ['./../g', bases[0], 'http://a/b/g'],
1327 ['./g/.', bases[0], 'http://a/b/c/g/'],
1328 ['g/./h', bases[0], 'http://a/b/c/g/h'],
1329 ['g/../h', bases[0], 'http://a/b/c/h'],
1330 ['g;x=1/./y', bases[0], 'http://a/b/c/g;x=1/y'],
1331 ['g;x=1/../y', bases[0], 'http://a/b/c/y'],
1332 ['g?y/./x', bases[0], 'http://a/b/c/g?y/./x'],
1333 ['g?y/../x', bases[0], 'http://a/b/c/g?y/../x'],
1334 ['g#s/./x', bases[0], 'http://a/b/c/g#s/./x'],
1335 ['g#s/../x', bases[0], 'http://a/b/c/g#s/../x'],
1336 ['http:g', bases[0], ('http:g', 'http://a/b/c/g')],
1337 ['http:', bases[0], ('http:', bases[0])],
1338 // not sure where this one originated
1339 ['/a/b/c/./../../g', bases[0], 'http://a/a/g'],
1340
1341 // http://gbiv.com/protocols/uri/test/rel_examples2.html
1342 // slashes in base URI's query args
1343 ['g', bases[1], 'http://a/b/c/g'],
1344 ['./g', bases[1], 'http://a/b/c/g'],
1345 ['g/', bases[1], 'http://a/b/c/g/'],
1346 ['/g', bases[1], 'http://a/g'],
1347 ['//g', bases[1], 'http://g/'],
1348 // changed in RFC 2396bis
1349 //('?y', bases[1], 'http://a/b/c/?y'],
1350 ['?y', bases[1], 'http://a/b/c/d;p?y'],
1351 ['g?y', bases[1], 'http://a/b/c/g?y'],
1352 ['g?y/./x' , bases[1], 'http://a/b/c/g?y/./x'],
1353 ['g?y/../x', bases[1], 'http://a/b/c/g?y/../x'],
1354 ['g#s', bases[1], 'http://a/b/c/g#s'],
1355 ['g#s/./x' , bases[1], 'http://a/b/c/g#s/./x'],
1356 ['g#s/../x', bases[1], 'http://a/b/c/g#s/../x'],
1357 ['./', bases[1], 'http://a/b/c/'],
1358 ['../', bases[1], 'http://a/b/'],
1359 ['../g', bases[1], 'http://a/b/g'],
1360 ['../../', bases[1], 'http://a/'],
1361 ['../../g' , bases[1], 'http://a/g'],
1362
1363 // http://gbiv.com/protocols/uri/test/rel_examples3.html
1364 // slashes in path params
1365 // all of these changed in RFC 2396bis
1366 ['g', bases[2], 'http://a/b/c/d;p=1/g'],
1367 ['./g', bases[2], 'http://a/b/c/d;p=1/g'],
1368 ['g/', bases[2], 'http://a/b/c/d;p=1/g/'],
1369 ['g?y', bases[2], 'http://a/b/c/d;p=1/g?y'],
1370 [';x', bases[2], 'http://a/b/c/d;p=1/;x'],
1371 ['g;x', bases[2], 'http://a/b/c/d;p=1/g;x'],
1372 ['g;x=1/./y', bases[2], 'http://a/b/c/d;p=1/g;x=1/y'],
1373 ['g;x=1/../y', bases[2], 'http://a/b/c/d;p=1/y'],
1374 ['./', bases[2], 'http://a/b/c/d;p=1/'],
1375 ['../', bases[2], 'http://a/b/c/'],
1376 ['../g', bases[2], 'http://a/b/c/g'],
1377 ['../../', bases[2], 'http://a/b/'],
1378 ['../../g' , bases[2], 'http://a/b/g'],
1379
1380 // http://gbiv.com/protocols/uri/test/rel_examples4.html
1381 // double and triple slash, unknown scheme
1382 ['g:h', bases[3], 'g:h'],
1383 ['g', bases[3], 'fred:///s//a/b/g'],
1384 ['./g', bases[3], 'fred:///s//a/b/g'],
1385 ['g/', bases[3], 'fred:///s//a/b/g/'],
1386 ['/g', bases[3], 'fred:///g'], // may change to fred:///s//a/g
1387 ['//g', bases[3], 'fred://g'], // may change to fred:///s//g
1388 ['//g/x', bases[3], 'fred://g/x'], // may change to fred:///s//g/x
1389 ['///g', bases[3], 'fred:///g'],
1390 ['./', bases[3], 'fred:///s//a/b/'],
1391 ['../', bases[3], 'fred:///s//a/'],
1392 ['../g', bases[3], 'fred:///s//a/g'],
1393
1394 ['../../', bases[3], 'fred:///s//'],
1395 ['../../g' , bases[3], 'fred:///s//g'],
1396 ['../../../g', bases[3], 'fred:///s/g'],
1397 // may change to fred:///s//a/../../../g
1398 ['../../../../g', bases[3], 'fred:///g'],
1399
1400 // http://gbiv.com/protocols/uri/test/rel_examples5.html
1401 // double and triple slash, well-known scheme
1402 ['g:h', bases[4], 'g:h'],
1403 ['g', bases[4], 'http:///s//a/b/g'],
1404 ['./g', bases[4], 'http:///s//a/b/g'],
1405 ['g/', bases[4], 'http:///s//a/b/g/'],
1406 ['/g', bases[4], 'http:///g'], // may change to http:///s//a/g
1407 ['//g', bases[4], 'http://g/'], // may change to http:///s//g
1408 ['//g/x', bases[4], 'http://g/x'], // may change to http:///s//g/x
1409 ['///g', bases[4], 'http:///g'],
1410 ['./', bases[4], 'http:///s//a/b/'],
1411 ['../', bases[4], 'http:///s//a/'],
1412 ['../g', bases[4], 'http:///s//a/g'],
1413 ['../../', bases[4], 'http:///s//'],
1414 ['../../g' , bases[4], 'http:///s//g'],
1415 // may change to http:///s//a/../../g
1416 ['../../../g', bases[4], 'http:///s/g'],
1417 // may change to http:///s//a/../../../g
1418 ['../../../../g', bases[4], 'http:///g'],
1419
1420 // from Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py
1421 ['bar:abc', 'foo:xyz', 'bar:abc'],
1422 ['../abc', 'http://example/x/y/z', 'http://example/x/abc'],
1423 ['http://example/x/abc', 'http://example2/x/y/z', 'http://example/x/abc'],
1424 ['../r', 'http://ex/x/y/z', 'http://ex/x/r'],
1425 ['q/r', 'http://ex/x/y', 'http://ex/x/q/r'],
1426 ['q/r#s', 'http://ex/x/y', 'http://ex/x/q/r#s'],
1427 ['q/r#s/t', 'http://ex/x/y', 'http://ex/x/q/r#s/t'],
1428 ['ftp://ex/x/q/r', 'http://ex/x/y', 'ftp://ex/x/q/r'],
1429 ['', 'http://ex/x/y', 'http://ex/x/y'],
1430 ['', 'http://ex/x/y/', 'http://ex/x/y/'],
1431 ['', 'http://ex/x/y/pdq', 'http://ex/x/y/pdq'],
1432 ['z/', 'http://ex/x/y/', 'http://ex/x/y/z/'],
1433 ['#Animal',
1434 'file:/swap/test/animal.rdf',
1435 'file:/swap/test/animal.rdf#Animal'],
1436 ['../abc', 'file:/e/x/y/z', 'file:/e/x/abc'],
1437 ['/example/x/abc', 'file:/example2/x/y/z', 'file:/example/x/abc'],
1438 ['../r', 'file:/ex/x/y/z', 'file:/ex/x/r'],
1439 ['/r', 'file:/ex/x/y/z', 'file:/r'],
1440 ['q/r', 'file:/ex/x/y', 'file:/ex/x/q/r'],
1441 ['q/r#s', 'file:/ex/x/y', 'file:/ex/x/q/r#s'],
1442 ['q/r#', 'file:/ex/x/y', 'file:/ex/x/q/r#'],
1443 ['q/r#s/t', 'file:/ex/x/y', 'file:/ex/x/q/r#s/t'],
1444 ['ftp://ex/x/q/r', 'file:/ex/x/y', 'ftp://ex/x/q/r'],
1445 ['', 'file:/ex/x/y', 'file:/ex/x/y'],
1446 ['', 'file:/ex/x/y/', 'file:/ex/x/y/'],
1447 ['', 'file:/ex/x/y/pdq', 'file:/ex/x/y/pdq'],
1448 ['z/', 'file:/ex/x/y/', 'file:/ex/x/y/z/'],
1449 ['file://meetings.example.com/cal#m1',
1450 'file:/devel/WWW/2000/10/swap/test/reluri-1.n3',
1451 'file://meetings.example.com/cal#m1'],
1452 ['file://meetings.example.com/cal#m1',
1453 'file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3',
1454 'file://meetings.example.com/cal#m1'],
1455 ['./#blort', 'file:/some/dir/foo', 'file:/some/dir/#blort'],
1456 ['./#', 'file:/some/dir/foo', 'file:/some/dir/#'],
1457 // Ryan Lee
1458 ['./', 'http://example/x/abc.efg', 'http://example/x/'],
1459
1460
1461 // Graham Klyne's tests
1462 // http://www.ninebynine.org/Software/HaskellUtils/Network/UriTest.xls
1463 // 01-31 are from Connelly's cases
1464
1465 // 32-49
1466 ['./q:r', 'http://ex/x/y', 'http://ex/x/q:r'],
1467 ['./p=q:r', 'http://ex/x/y', 'http://ex/x/p=q:r'],
1468 ['?pp/rr', 'http://ex/x/y?pp/qq', 'http://ex/x/y?pp/rr'],
1469 ['y/z', 'http://ex/x/y?pp/qq', 'http://ex/x/y/z'],
1470 ['local/qual@domain.org#frag',
1471 'mailto:local',
1472 'mailto:local/qual@domain.org#frag'],
1473 ['more/qual2@domain2.org#frag',
1474 'mailto:local/qual1@domain1.org',
1475 'mailto:local/more/qual2@domain2.org#frag'],
1476 ['y?q', 'http://ex/x/y?q', 'http://ex/x/y?q'],
1477 ['/x/y?q', 'http://ex?p', 'http://ex/x/y?q'],
1478 ['c/d', 'foo:a/b', 'foo:a/c/d'],
1479 ['/c/d', 'foo:a/b', 'foo:/c/d'],
1480 ['', 'foo:a/b?c#d', 'foo:a/b?c'],
1481 ['b/c', 'foo:a', 'foo:b/c'],
1482 ['../b/c', 'foo:/a/y/z', 'foo:/a/b/c'],
1483 ['./b/c', 'foo:a', 'foo:b/c'],
1484 ['/./b/c', 'foo:a', 'foo:/b/c'],
1485 ['../../d', 'foo://a//b/c', 'foo://a/d'],
1486 ['.', 'foo:a', 'foo:'],
1487 ['..', 'foo:a', 'foo:'],
1488
1489 // 50-57[cf. TimBL comments --
1490 // http://lists.w3.org/Archives/Public/uri/2003Feb/0028.html,
1491 // http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html)
1492 ['abc', 'http://example/x/y%2Fz', 'http://example/x/abc'],
1493 ['../../x%2Fabc', 'http://example/a/x/y/z', 'http://example/a/x%2Fabc'],
1494 ['../x%2Fabc', 'http://example/a/x/y%2Fz', 'http://example/a/x%2Fabc'],
1495 ['abc', 'http://example/x%2Fy/z', 'http://example/x%2Fy/abc'],
1496 ['q%3Ar', 'http://ex/x/y', 'http://ex/x/q%3Ar'],
1497 ['/x%2Fabc', 'http://example/x/y%2Fz', 'http://example/x%2Fabc'],
1498 ['/x%2Fabc', 'http://example/x/y/z', 'http://example/x%2Fabc'],
1499 ['/x%2Fabc', 'http://example/x/y%2Fz', 'http://example/x%2Fabc'],
1500
1501 // 70-77
1502 ['local2@domain2', 'mailto:local1@domain1?query1', 'mailto:local2@domain2'],
1503 ['local2@domain2?query2',
1504 'mailto:local1@domain1',
1505 'mailto:local2@domain2?query2'],
1506 ['local2@domain2?query2',
1507 'mailto:local1@domain1?query1',
1508 'mailto:local2@domain2?query2'],
1509 ['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'],
1510 ['local@domain?query2', 'mailto:?query1', 'mailto:local@domain?query2'],
1511 ['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'],
1512 ['http://example/a/b?c/../d', 'foo:bar', 'http://example/a/b?c/../d'],
1513 ['http://example/a/b#c/../d', 'foo:bar', 'http://example/a/b#c/../d'],
1514
1515 // 82-88
1516 // @isaacs Disagree. Not how browsers do it.
1517 // ['http:this', 'http://example.org/base/uri', 'http:this'],
1518 // @isaacs Added
1519 ['http:this', 'http://example.org/base/uri', 'http://example.org/base/this'],
1520 ['http:this', 'http:base', 'http:this'],
1521 ['.//g', 'f:/a', 'f://g'],
1522 ['b/c//d/e', 'f://example.org/base/a', 'f://example.org/base/b/c//d/e'],
1523 ['m2@example.ord/c2@example.org',
1524 'mid:m@example.ord/c@example.org',
1525 'mid:m@example.ord/m2@example.ord/c2@example.org'],
1526 ['mini1.xml',
1527 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/',
1528 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml'],
1529 ['../b/c', 'foo:a/y/z', 'foo:a/b/c'],
1530
1531 //changeing auth
1532 ['http://diff:auth@www.example.com',
1533 'http://asdf:qwer@www.example.com',
1534 'http://diff:auth@www.example.com/']
1535];
1536
1537relativeTests2.forEach(function(relativeTest) {
1538 test('resolve(' + [relativeTest[1], relativeTest[0]] + ')', function() {
1539 var a = url.resolve(relativeTest[1], relativeTest[0]),
1540 e = relativeTest[2];
1541 assert.equal(a, e,
1542 'resolve(' + [relativeTest[1], relativeTest[0]] + ') == ' + e +
1543 '\n actual=' + a);
1544 });
1545});
1546
1547//if format and parse are inverse operations then
1548//resolveObject(parse(x), y) == parse(resolve(x, y))
1549
1550//host and hostname are special, in this case a '' value is important
1551var emptyIsImportant = {'host': true, 'hostname': ''};
1552
1553//format: [from, path, expected]
1554relativeTests.forEach(function(relativeTest) {
1555test('resolveObject(' + [relativeTest[0], relativeTest[1]] + ')', function() {
1556 var actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]),
1557 expected = url.parse(relativeTest[2]);
1558
1559
1560 assert.deepEqual(actual, expected);
1561
1562 expected = relativeTest[2];
1563 actual = url.format(actual);
1564
1565 assert.equal(actual, expected,
1566 'format(' + actual + ') == ' + expected + '\nactual:' + actual);
1567 });
1568});
1569
1570//format: [to, from, result]
1571// the test: ['.//g', 'f:/a', 'f://g'] is a fundamental problem
1572// url.parse('f:/a') does not have a host
1573// url.resolve('f:/a', './/g') does not have a host because you have moved
1574// down to the g directory. i.e. f: //g, however when this url is parsed
1575// f:// will indicate that the host is g which is not the case.
1576// it is unclear to me how to keep this information from being lost
1577// it may be that a pathname of ////g should collapse to /g but this seems
1578// to be a lot of work for an edge case. Right now I remove the test
1579if (relativeTests2[181][0] === './/g' &&
1580 relativeTests2[181][1] === 'f:/a' &&
1581 relativeTests2[181][2] === 'f://g') {
1582 relativeTests2.splice(181, 1);
1583}
1584
1585relativeTests2.forEach(function(relativeTest) {
1586 test('resolveObject(' + [relativeTest[1], relativeTest[0]] + ')', function() {
1587 var actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]),
1588 expected = url.parse(relativeTest[2]);
1589
1590 assert.deepEqual(actual, expected);
1591
1592 var expected = relativeTest[2],
1593 actual = url.format(actual);
1594
1595 assert.equal(actual, expected,
1596 'format(' + relativeTest[1] + ') == ' + expected +
1597 '\nactual:' + actual);
1598 });
1599});
Note: See TracBrowser for help on using the repository browser.