react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / url / test.js
80708 views// Copyright Joyent, Inc. and other Node contributors.1//2// Permission is hereby granted, free of charge, to any person obtaining a3// copy of this software and associated documentation files (the4// "Software"), to deal in the Software without restriction, including5// without limitation the rights to use, copy, modify, merge, publish,6// distribute, sublicense, and/or sell copies of the Software, and to permit7// persons to whom the Software is furnished to do so, subject to the8// following conditions:9//10// The above copyright notice and this permission notice shall be included11// in all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS14// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF15// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN16// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,17// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR18// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE19// USE OR OTHER DEALINGS IN THE SOFTWARE.2021var assert = require('assert');22var util = require('util');2324var url = require('./url');2526test('god', function() {2728// URLs to parse, and expected data29// { url : parsed }30var parseTests = {31'//some_path' : {32'href': '//some_path',33'pathname': '//some_path',34'path': '//some_path'35},3637'HTTP://www.example.com/' : {38'href': 'http://www.example.com/',39'protocol': 'http:',40'slashes': true,41'host': 'www.example.com',42'hostname': 'www.example.com',43'pathname': '/',44'path': '/'45},4647'HTTP://www.example.com' : {48'href': 'http://www.example.com/',49'protocol': 'http:',50'slashes': true,51'host': 'www.example.com',52'hostname': 'www.example.com',53'pathname': '/',54'path': '/'55},5657'http://www.ExAmPlE.com/' : {58'href': 'http://www.example.com/',59'protocol': 'http:',60'slashes': true,61'host': 'www.example.com',62'hostname': 'www.example.com',63'pathname': '/',64'path': '/'65},6667'http://user:[email protected]/' : {68'href': 'http://user:[email protected]/',69'protocol': 'http:',70'slashes': true,71'auth': 'user:pw',72'host': 'www.example.com',73'hostname': 'www.example.com',74'pathname': '/',75'path': '/'76},7778'http://USER:[email protected]/' : {79'href': 'http://USER:[email protected]/',80'protocol': 'http:',81'slashes': true,82'auth': 'USER:PW',83'host': 'www.example.com',84'hostname': 'www.example.com',85'pathname': '/',86'path': '/'87},8889'http://[email protected]/' : {90'href': 'http://[email protected]/',91'protocol': 'http:',92'slashes': true,93'auth': 'user',94'host': 'www.example.com',95'hostname': 'www.example.com',96'pathname': '/',97'path': '/'98},99100'http://user%[email protected]/' : {101'href': 'http://user:[email protected]/',102'protocol': 'http:',103'slashes': true,104'auth': 'user:pw',105'host': 'www.example.com',106'hostname': 'www.example.com',107'pathname': '/',108'path': '/'109},110111'http://x.com/path?that\'s#all, folks' : {112'href': 'http://x.com/path?that%27s#all,%20folks',113'protocol': 'http:',114'slashes': true,115'host': 'x.com',116'hostname': 'x.com',117'search': '?that%27s',118'query': 'that%27s',119'pathname': '/path',120'hash': '#all,%20folks',121'path': '/path?that%27s'122},123124'HTTP://X.COM/Y' : {125'href': 'http://x.com/Y',126'protocol': 'http:',127'slashes': true,128'host': 'x.com',129'hostname': 'x.com',130'pathname': '/Y',131'path': '/Y'132},133134// an unexpected invalid char in the hostname.135'HtTp://x.y.cOm*a/b/c?d=e#f g<h>i' : {136'href': 'http://x.y.com/*a/b/c?d=e#f%20g%3Ch%3Ei',137'protocol': 'http:',138'slashes': true,139'host': 'x.y.com',140'hostname': 'x.y.com',141'pathname': '/*a/b/c',142'search': '?d=e',143'query': 'd=e',144'hash': '#f%20g%3Ch%3Ei',145'path': '/*a/b/c?d=e'146},147148// make sure that we don't accidentally lcast the path parts.149'HtTp://x.y.cOm*A/b/c?d=e#f g<h>i' : {150'href': 'http://x.y.com/*A/b/c?d=e#f%20g%3Ch%3Ei',151'protocol': 'http:',152'slashes': true,153'host': 'x.y.com',154'hostname': 'x.y.com',155'pathname': '/*A/b/c',156'search': '?d=e',157'query': 'd=e',158'hash': '#f%20g%3Ch%3Ei',159'path': '/*A/b/c?d=e'160},161162'http://x...y...#p': {163'href': 'http://x...y.../#p',164'protocol': 'http:',165'slashes': true,166'host': 'x...y...',167'hostname': 'x...y...',168'hash': '#p',169'pathname': '/',170'path': '/'171},172173'http://x/p/"quoted"': {174'href': 'http://x/p/%22quoted%22',175'protocol': 'http:',176'slashes': true,177'host': 'x',178'hostname': 'x',179'pathname': '/p/%22quoted%22',180'path': '/p/%22quoted%22'181},182183'<http://goo.corn/bread> Is a URL!': {184'href': '%3Chttp://goo.corn/bread%3E%20Is%20a%20URL!',185'pathname': '%3Chttp://goo.corn/bread%3E%20Is%20a%20URL!',186'path': '%3Chttp://goo.corn/bread%3E%20Is%20a%20URL!'187},188189'http://www.narwhaljs.org/blog/categories?id=news' : {190'href': 'http://www.narwhaljs.org/blog/categories?id=news',191'protocol': 'http:',192'slashes': true,193'host': 'www.narwhaljs.org',194'hostname': 'www.narwhaljs.org',195'search': '?id=news',196'query': 'id=news',197'pathname': '/blog/categories',198'path': '/blog/categories?id=news'199},200201'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=' : {202'href': 'http://mt0.google.com/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=',203'protocol': 'http:',204'slashes': true,205'host': 'mt0.google.com',206'hostname': 'mt0.google.com',207'pathname': '/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s=',208'path': '/vt/lyrs=m@114&hl=en&src=api&x=2&y=2&z=3&s='209},210211'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=' : {212'href': 'http://mt0.google.com/vt/lyrs=m@114???&hl=en&src=api' +213'&x=2&y=2&z=3&s=',214'protocol': 'http:',215'slashes': true,216'host': 'mt0.google.com',217'hostname': 'mt0.google.com',218'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',219'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',220'pathname': '/vt/lyrs=m@114',221'path': '/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s='222},223224'http://user:[email protected]/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s=':225{226'href': 'http://user:[email protected]/vt/lyrs=m@114???' +227'&hl=en&src=api&x=2&y=2&z=3&s=',228'protocol': 'http:',229'slashes': true,230'host': 'mt0.google.com',231'auth': 'user:pass',232'hostname': 'mt0.google.com',233'search': '???&hl=en&src=api&x=2&y=2&z=3&s=',234'query': '??&hl=en&src=api&x=2&y=2&z=3&s=',235'pathname': '/vt/lyrs=m@114',236'path': '/vt/lyrs=m@114???&hl=en&src=api&x=2&y=2&z=3&s='237},238239'file:///etc/passwd' : {240'href': 'file:///etc/passwd',241'slashes': true,242'protocol': 'file:',243'pathname': '/etc/passwd',244'hostname': '',245'host': '',246'path': '/etc/passwd'247},248249'file://localhost/etc/passwd' : {250'href': 'file://localhost/etc/passwd',251'protocol': 'file:',252'slashes': true,253'pathname': '/etc/passwd',254'hostname': 'localhost',255'host': 'localhost',256'path': '/etc/passwd'257},258259'file://foo/etc/passwd' : {260'href': 'file://foo/etc/passwd',261'protocol': 'file:',262'slashes': true,263'pathname': '/etc/passwd',264'hostname': 'foo',265'host': 'foo',266'path': '/etc/passwd'267},268269'file:///etc/node/' : {270'href': 'file:///etc/node/',271'slashes': true,272'protocol': 'file:',273'pathname': '/etc/node/',274'hostname': '',275'host': '',276'path': '/etc/node/'277},278279'file://localhost/etc/node/' : {280'href': 'file://localhost/etc/node/',281'protocol': 'file:',282'slashes': true,283'pathname': '/etc/node/',284'hostname': 'localhost',285'host': 'localhost',286'path': '/etc/node/'287},288289'file://foo/etc/node/' : {290'href': 'file://foo/etc/node/',291'protocol': 'file:',292'slashes': true,293'pathname': '/etc/node/',294'hostname': 'foo',295'host': 'foo',296'path': '/etc/node/'297},298299'http:/baz/../foo/bar' : {300'href': 'http:/baz/../foo/bar',301'protocol': 'http:',302'pathname': '/baz/../foo/bar',303'path': '/baz/../foo/bar'304},305306'http://user:[email protected]:8000/foo/bar?baz=quux#frag' : {307'href': 'http://user:[email protected]:8000/foo/bar?baz=quux#frag',308'protocol': 'http:',309'slashes': true,310'host': 'example.com:8000',311'auth': 'user:pass',312'port': '8000',313'hostname': 'example.com',314'hash': '#frag',315'search': '?baz=quux',316'query': 'baz=quux',317'pathname': '/foo/bar',318'path': '/foo/bar?baz=quux'319},320321'//user:[email protected]:8000/foo/bar?baz=quux#frag' : {322'href': '//user:[email protected]:8000/foo/bar?baz=quux#frag',323'slashes': true,324'host': 'example.com:8000',325'auth': 'user:pass',326'port': '8000',327'hostname': 'example.com',328'hash': '#frag',329'search': '?baz=quux',330'query': 'baz=quux',331'pathname': '/foo/bar',332'path': '/foo/bar?baz=quux'333},334335'/foo/bar?baz=quux#frag' : {336'href': '/foo/bar?baz=quux#frag',337'hash': '#frag',338'search': '?baz=quux',339'query': 'baz=quux',340'pathname': '/foo/bar',341'path': '/foo/bar?baz=quux'342},343344'http:/foo/bar?baz=quux#frag' : {345'href': 'http:/foo/bar?baz=quux#frag',346'protocol': 'http:',347'hash': '#frag',348'search': '?baz=quux',349'query': 'baz=quux',350'pathname': '/foo/bar',351'path': '/foo/bar?baz=quux'352},353354'mailto:[email protected]?subject=hello' : {355'href': 'mailto:[email protected]?subject=hello',356'protocol': 'mailto:',357'host': 'bar.com',358'auth' : 'foo',359'hostname' : 'bar.com',360'search': '?subject=hello',361'query': 'subject=hello',362'path': '?subject=hello'363},364365'javascript:alert(\'hello\');' : {366'href': 'javascript:alert(\'hello\');',367'protocol': 'javascript:',368'pathname': 'alert(\'hello\');',369'path': 'alert(\'hello\');'370},371372'xmpp:[email protected]' : {373'href': 'xmpp:[email protected]',374'protocol': 'xmpp:',375'host': 'jabber.org',376'auth': 'isaacschlueter',377'hostname': 'jabber.org'378},379380'http://atpass:foo%[email protected]:8080/path?search=foo#bar' : {381'href' : 'http://atpass:foo%[email protected]:8080/path?search=foo#bar',382'protocol' : 'http:',383'slashes': true,384'host' : '127.0.0.1:8080',385'auth' : 'atpass:foo@bar',386'hostname' : '127.0.0.1',387'port' : '8080',388'pathname': '/path',389'search' : '?search=foo',390'query' : 'search=foo',391'hash' : '#bar',392'path': '/path?search=foo'393},394395'svn+ssh://foo/bar': {396'href': 'svn+ssh://foo/bar',397'host': 'foo',398'hostname': 'foo',399'protocol': 'svn+ssh:',400'pathname': '/bar',401'path': '/bar',402'slashes': true403},404405'dash-test://foo/bar': {406'href': 'dash-test://foo/bar',407'host': 'foo',408'hostname': 'foo',409'protocol': 'dash-test:',410'pathname': '/bar',411'path': '/bar',412'slashes': true413},414415'dash-test:foo/bar': {416'href': 'dash-test:foo/bar',417'host': 'foo',418'hostname': 'foo',419'protocol': 'dash-test:',420'pathname': '/bar',421'path': '/bar'422},423424'dot.test://foo/bar': {425'href': 'dot.test://foo/bar',426'host': 'foo',427'hostname': 'foo',428'protocol': 'dot.test:',429'pathname': '/bar',430'path': '/bar',431'slashes': true432},433434'dot.test:foo/bar': {435'href': 'dot.test:foo/bar',436'host': 'foo',437'hostname': 'foo',438'protocol': 'dot.test:',439'pathname': '/bar',440'path': '/bar'441},442443// IDNA tests444'http://www.日本語.com/' : {445'href': 'http://www.xn--wgv71a119e.com/',446'protocol': 'http:',447'slashes': true,448'host': 'www.xn--wgv71a119e.com',449'hostname': 'www.xn--wgv71a119e.com',450'pathname': '/',451'path': '/'452},453454'http://example.Bücher.com/' : {455'href': 'http://example.xn--bcher-kva.com/',456'protocol': 'http:',457'slashes': true,458'host': 'example.xn--bcher-kva.com',459'hostname': 'example.xn--bcher-kva.com',460'pathname': '/',461'path': '/'462},463464'http://www.Äffchen.com/' : {465'href': 'http://www.xn--ffchen-9ta.com/',466'protocol': 'http:',467'slashes': true,468'host': 'www.xn--ffchen-9ta.com',469'hostname': 'www.xn--ffchen-9ta.com',470'pathname': '/',471'path': '/'472},473474'http://www.Äffchen.cOm*A/b/c?d=e#f g<h>i' : {475'href': 'http://www.xn--ffchen-9ta.com/*A/b/c?d=e#f%20g%3Ch%3Ei',476'protocol': 'http:',477'slashes': true,478'host': 'www.xn--ffchen-9ta.com',479'hostname': 'www.xn--ffchen-9ta.com',480'pathname': '/*A/b/c',481'search': '?d=e',482'query': 'd=e',483'hash': '#f%20g%3Ch%3Ei',484'path': '/*A/b/c?d=e'485},486487'http://SÉLIER.COM/' : {488'href': 'http://xn--slier-bsa.com/',489'protocol': 'http:',490'slashes': true,491'host': 'xn--slier-bsa.com',492'hostname': 'xn--slier-bsa.com',493'pathname': '/',494'path': '/'495},496497'http://ليهمابتكلموشعربي؟.ي؟/' : {498'href': 'http://xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f/',499'protocol': 'http:',500'slashes': true,501'host': 'xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f',502'hostname': 'xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f',503'pathname': '/',504'path': '/'505},506507'http://➡.ws/➡' : {508'href': 'http://xn--hgi.ws/➡',509'protocol': 'http:',510'slashes': true,511'host': 'xn--hgi.ws',512'hostname': 'xn--hgi.ws',513'pathname': '/➡',514'path': '/➡'515},516517'http://bucket_name.s3.amazonaws.com/image.jpg': {518protocol: 'http:',519slashes: true,520host: 'bucket_name.s3.amazonaws.com',521hostname: 'bucket_name.s3.amazonaws.com',522pathname: '/image.jpg',523href: 'http://bucket_name.s3.amazonaws.com/image.jpg',524'path': '/image.jpg'525},526527'git+http://github.com/joyent/node.git': {528protocol: 'git+http:',529slashes: true,530host: 'github.com',531hostname: 'github.com',532pathname: '/joyent/node.git',533path: '/joyent/node.git',534href: 'git+http://github.com/joyent/node.git'535},536537//if local1@domain1 is uses as a relative URL it may538//be parse into auth@hostname, but here there is no539//way to make it work in url.parse, I add the test to be explicit540'local1@domain1': {541'pathname': 'local1@domain1',542'path': 'local1@domain1',543'href': 'local1@domain1'544},545546//While this may seem counter-intuitive, a browser will parse547//<a href='www.google.com'> as a path.548'www.example.com' : {549'href': 'www.example.com',550'pathname': 'www.example.com',551'path': 'www.example.com'552},553554// ipv6 support555'[fe80::1]': {556'href': '[fe80::1]',557'pathname': '[fe80::1]',558'path': '[fe80::1]'559},560561'coap://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]': {562'protocol': 'coap:',563'slashes': true,564'host': '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]',565'hostname': 'fedc:ba98:7654:3210:fedc:ba98:7654:3210',566'href': 'coap://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/',567'pathname': '/',568'path': '/'569},570571'coap://[1080:0:0:0:8:800:200C:417A]:61616/': {572'protocol': 'coap:',573'slashes': true,574'host': '[1080:0:0:0:8:800:200c:417a]:61616',575'port': '61616',576'hostname': '1080:0:0:0:8:800:200c:417a',577'href': 'coap://[1080:0:0:0:8:800:200c:417a]:61616/',578'pathname': '/',579'path': '/'580},581582'http://user:password@[3ffe:2a00:100:7031::1]:8080': {583'protocol': 'http:',584'slashes': true,585'auth': 'user:password',586'host': '[3ffe:2a00:100:7031::1]:8080',587'port': '8080',588'hostname': '3ffe:2a00:100:7031::1',589'href': 'http://user:password@[3ffe:2a00:100:7031::1]:8080/',590'pathname': '/',591'path': '/'592},593594'coap://u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature': {595'protocol': 'coap:',596'slashes': true,597'auth': 'u:p',598'host': '[::192.9.5.5]:61616',599'port': '61616',600'hostname': '::192.9.5.5',601'href': 'coap://u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature',602'search': '?n=Temperature',603'query': 'n=Temperature',604'pathname': '/.well-known/r',605'path': '/.well-known/r?n=Temperature'606},607608// empty port609'http://example.com:': {610'protocol': 'http:',611'slashes': true,612'host': 'example.com',613'hostname': 'example.com',614'href': 'http://example.com/',615'pathname': '/',616'path': '/'617},618619'http://example.com:/a/b.html': {620'protocol': 'http:',621'slashes': true,622'host': 'example.com',623'hostname': 'example.com',624'href': 'http://example.com/a/b.html',625'pathname': '/a/b.html',626'path': '/a/b.html'627},628629'http://example.com:?a=b': {630'protocol': 'http:',631'slashes': true,632'host': 'example.com',633'hostname': 'example.com',634'href': 'http://example.com/?a=b',635'search': '?a=b',636'query': 'a=b',637'pathname': '/',638'path': '/?a=b'639},640641'http://example.com:#abc': {642'protocol': 'http:',643'slashes': true,644'host': 'example.com',645'hostname': 'example.com',646'href': 'http://example.com/#abc',647'hash': '#abc',648'pathname': '/',649'path': '/'650},651652'http://[fe80::1]:/a/b?a=b#abc': {653'protocol': 'http:',654'slashes': true,655'host': '[fe80::1]',656'hostname': 'fe80::1',657'href': 'http://[fe80::1]/a/b?a=b#abc',658'search': '?a=b',659'query': 'a=b',660'hash': '#abc',661'pathname': '/a/b',662'path': '/a/b?a=b'663},664665'http://-lovemonsterz.tumblr.com/rss': {666'protocol': 'http:',667'slashes': true,668'host': '-lovemonsterz.tumblr.com',669'hostname': '-lovemonsterz.tumblr.com',670'href': 'http://-lovemonsterz.tumblr.com/rss',671'pathname': '/rss',672'path': '/rss',673},674675'http://-lovemonsterz.tumblr.com:80/rss': {676'protocol': 'http:',677'slashes': true,678'port': '80',679'host': '-lovemonsterz.tumblr.com:80',680'hostname': '-lovemonsterz.tumblr.com',681'href': 'http://-lovemonsterz.tumblr.com:80/rss',682'pathname': '/rss',683'path': '/rss',684},685686'http://user:[email protected]/rss': {687'protocol': 'http:',688'slashes': true,689'auth': 'user:pass',690'host': '-lovemonsterz.tumblr.com',691'hostname': '-lovemonsterz.tumblr.com',692'href': 'http://user:[email protected]/rss',693'pathname': '/rss',694'path': '/rss',695},696697'http://user:[email protected]:80/rss': {698'protocol': 'http:',699'slashes': true,700'auth': 'user:pass',701'port': '80',702'host': '-lovemonsterz.tumblr.com:80',703'hostname': '-lovemonsterz.tumblr.com',704'href': 'http://user:[email protected]:80/rss',705'pathname': '/rss',706'path': '/rss',707},708709'http://_jabber._tcp.google.com/test': {710'protocol': 'http:',711'slashes': true,712'host': '_jabber._tcp.google.com',713'hostname': '_jabber._tcp.google.com',714'href': 'http://_jabber._tcp.google.com/test',715'pathname': '/test',716'path': '/test',717},718719'http://user:pass@_jabber._tcp.google.com/test': {720'protocol': 'http:',721'slashes': true,722'auth': 'user:pass',723'host': '_jabber._tcp.google.com',724'hostname': '_jabber._tcp.google.com',725'href': 'http://user:pass@_jabber._tcp.google.com/test',726'pathname': '/test',727'path': '/test',728},729730'http://_jabber._tcp.google.com:80/test': {731'protocol': 'http:',732'slashes': true,733'port': '80',734'host': '_jabber._tcp.google.com:80',735'hostname': '_jabber._tcp.google.com',736'href': 'http://_jabber._tcp.google.com:80/test',737'pathname': '/test',738'path': '/test',739},740741'http://user:pass@_jabber._tcp.google.com:80/test': {742'protocol': 'http:',743'slashes': true,744'auth': 'user:pass',745'port': '80',746'host': '_jabber._tcp.google.com:80',747'hostname': '_jabber._tcp.google.com',748'href': 'http://user:pass@_jabber._tcp.google.com:80/test',749'pathname': '/test',750'path': '/test',751},752753'http://a@b@c/': {754protocol: 'http:',755slashes: true,756auth: 'a@b',757host: 'c',758hostname: 'c',759href: 'http://a%40b@c/',760path: '/',761pathname: '/'762},763764'http://a@b?@c': {765protocol: 'http:',766slashes: true,767auth: 'a',768host: 'b',769hostname: 'b',770href: 'http://a@b/?@c',771path: '/?@c',772pathname: '/',773search: '?@c',774query: '@c'775},776777'http://a\r" \t\n<\'b:b@c\r\nd/e?f':{778protocol: 'http:',779slashes: true,780auth: 'a\r" \t\n<\'b:b',781host: 'c',782port: null,783hostname: 'c',784hash: null,785search: '?f',786query: 'f',787pathname: '%0D%0Ad/e',788path: '%0D%0Ad/e?f',789href: 'http://a%0D%22%20%09%0A%3C\'b:b@c/%0D%0Ad/e?f'790}791792};793794for (var u in parseTests) {795var actual = url.parse(u),796spaced = url.parse(' \t ' + u + '\n\t');797expected = parseTests[u];798799Object.keys(actual).forEach(function (i) {800if (expected[i] === undefined && actual[i] === null) {801expected[i] = null;802}803});804805assert.deepEqual(actual, expected);806assert.deepEqual(spaced, expected);807808var expected = parseTests[u].href,809actual = url.format(parseTests[u]);810811assert.equal(actual, expected,812'format(' + u + ') == ' + u + '\nactual:' + actual);813}814815var parseTestsWithQueryString = {816'/foo/bar?baz=quux#frag' : {817'href': '/foo/bar?baz=quux#frag',818'hash': '#frag',819'search': '?baz=quux',820'query': {821'baz': 'quux'822},823'pathname': '/foo/bar',824'path': '/foo/bar?baz=quux'825},826'http://example.com' : {827'href': 'http://example.com/',828'protocol': 'http:',829'slashes': true,830'host': 'example.com',831'hostname': 'example.com',832'query': {},833'search': '',834'pathname': '/',835'path': '/'836}837};838for (var u in parseTestsWithQueryString) {839var actual = url.parse(u, true);840var expected = parseTestsWithQueryString[u];841for (var i in actual) {842if (actual[i] === null && expected[i] === undefined) {843expected[i] = null;844}845}846847assert.deepEqual(actual, expected);848}849850// some extra formatting tests, just to verify851// that it'll format slightly wonky content to a valid url.852var formatTests = {853'http://example.com?' : {854'href': 'http://example.com/?',855'protocol': 'http:',856'slashes': true,857'host': 'example.com',858'hostname': 'example.com',859'search': '?',860'query': {},861'pathname': '/'862},863'http://example.com?foo=bar#frag' : {864'href': 'http://example.com/?foo=bar#frag',865'protocol': 'http:',866'host': 'example.com',867'hostname': 'example.com',868'hash': '#frag',869'search': '?foo=bar',870'query': 'foo=bar',871'pathname': '/'872},873'http://example.com?foo=@bar#frag' : {874'href': 'http://example.com/?foo=@bar#frag',875'protocol': 'http:',876'host': 'example.com',877'hostname': 'example.com',878'hash': '#frag',879'search': '?foo=@bar',880'query': 'foo=@bar',881'pathname': '/'882},883'http://example.com?foo=/bar/#frag' : {884'href': 'http://example.com/?foo=/bar/#frag',885'protocol': 'http:',886'host': 'example.com',887'hostname': 'example.com',888'hash': '#frag',889'search': '?foo=/bar/',890'query': 'foo=/bar/',891'pathname': '/'892},893'http://example.com?foo=?bar/#frag' : {894'href': 'http://example.com/?foo=?bar/#frag',895'protocol': 'http:',896'host': 'example.com',897'hostname': 'example.com',898'hash': '#frag',899'search': '?foo=?bar/',900'query': 'foo=?bar/',901'pathname': '/'902},903'http://example.com#frag=?bar/#frag' : {904'href': 'http://example.com/#frag=?bar/#frag',905'protocol': 'http:',906'host': 'example.com',907'hostname': 'example.com',908'hash': '#frag=?bar/#frag',909'pathname': '/'910},911'http://google.com" onload="alert(42)/' : {912'href': 'http://google.com/%22%20onload=%22alert(42)/',913'protocol': 'http:',914'host': 'google.com',915'pathname': '/%22%20onload=%22alert(42)/'916},917'http://a.com/a/b/c?s#h' : {918'href': 'http://a.com/a/b/c?s#h',919'protocol': 'http',920'host': 'a.com',921'pathname': 'a/b/c',922'hash': 'h',923'search': 's'924},925'xmpp:[email protected]' : {926'href': 'xmpp:[email protected]',927'protocol': 'xmpp:',928'host': 'jabber.org',929'auth': 'isaacschlueter',930'hostname': 'jabber.org'931},932'http://atpass:foo%[email protected]/' : {933'href': 'http://atpass:foo%[email protected]/',934'auth': 'atpass:foo@bar',935'hostname': '127.0.0.1',936'protocol': 'http:',937'pathname': '/'938},939'http://atslash%2F%40:%2F%40@foo/' : {940'href': 'http://atslash%2F%40:%2F%40@foo/',941'auth': 'atslash/@:/@',942'hostname': 'foo',943'protocol': 'http:',944'pathname': '/'945},946'svn+ssh://foo/bar': {947'href': 'svn+ssh://foo/bar',948'hostname': 'foo',949'protocol': 'svn+ssh:',950'pathname': '/bar',951'slashes': true952},953'dash-test://foo/bar': {954'href': 'dash-test://foo/bar',955'hostname': 'foo',956'protocol': 'dash-test:',957'pathname': '/bar',958'slashes': true959},960'dash-test:foo/bar': {961'href': 'dash-test:foo/bar',962'hostname': 'foo',963'protocol': 'dash-test:',964'pathname': '/bar'965},966'dot.test://foo/bar': {967'href': 'dot.test://foo/bar',968'hostname': 'foo',969'protocol': 'dot.test:',970'pathname': '/bar',971'slashes': true972},973'dot.test:foo/bar': {974'href': 'dot.test:foo/bar',975'hostname': 'foo',976'protocol': 'dot.test:',977'pathname': '/bar'978},979// ipv6 support980'coap:u:p@[::1]:61616/.well-known/r?n=Temperature': {981'href': 'coap:u:p@[::1]:61616/.well-known/r?n=Temperature',982'protocol': 'coap:',983'auth': 'u:p',984'hostname': '::1',985'port': '61616',986'pathname': '/.well-known/r',987'search': 'n=Temperature'988},989'coap:[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616/s/stopButton': {990'href': 'coap:[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616/s/stopButton',991'protocol': 'coap',992'host': '[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616',993'pathname': '/s/stopButton'994},995996// encode context-specific delimiters in path and query, but do not touch997// other non-delimiter chars like `%`.998// <https://github.com/joyent/node/issues/4082>9991000// `#`,`?` in path1001'/path/to/%%23%3F+=&.txt?foo=theA1#bar' : {1002href : '/path/to/%%23%3F+=&.txt?foo=theA1#bar',1003pathname: '/path/to/%#?+=&.txt',1004query: {1005foo: 'theA1'1006},1007hash: "#bar"1008},10091010// `#`,`?` in path + `#` in query1011'/path/to/%%23%3F+=&.txt?foo=the%231#bar' : {1012href : '/path/to/%%23%3F+=&.txt?foo=the%231#bar',1013pathname: '/path/to/%#?+=&.txt',1014query: {1015foo: 'the#1'1016},1017hash: "#bar"1018},10191020// `?` and `#` in path and search1021'http://ex.com/foo%3F100%m%23r?abc=the%231?&foo=bar#frag': {1022href: 'http://ex.com/foo%3F100%m%23r?abc=the%231?&foo=bar#frag',1023protocol: 'http:',1024hostname: 'ex.com',1025hash: '#frag',1026search: '?abc=the#1?&foo=bar',1027pathname: '/foo?100%m#r',1028},10291030// `?` and `#` in search only1031'http://ex.com/fooA100%mBr?abc=the%231?&foo=bar#frag': {1032href: 'http://ex.com/fooA100%mBr?abc=the%231?&foo=bar#frag',1033protocol: 'http:',1034hostname: 'ex.com',1035hash: '#frag',1036search: '?abc=the#1?&foo=bar',1037pathname: '/fooA100%mBr',1038}1039};1040for (var u in formatTests) {1041var expect = formatTests[u].href;1042delete formatTests[u].href;1043var actual = url.format(u);1044var actualObj = url.format(formatTests[u]);1045assert.equal(actual, expect,1046'wonky format(' + u + ') == ' + expect +1047'\nactual:' + actual);1048assert.equal(actualObj, expect,1049'wonky format(' + JSON.stringify(formatTests[u]) +1050') == ' + expect +1051'\nactual: ' + actualObj);1052}10531054/*1055[from, path, expected]1056*/1057var relativeTests = [1058['/foo/bar/baz', 'quux', '/foo/bar/quux'],1059['/foo/bar/baz', 'quux/asdf', '/foo/bar/quux/asdf'],1060['/foo/bar/baz', 'quux/baz', '/foo/bar/quux/baz'],1061['/foo/bar/baz', '../quux/baz', '/foo/quux/baz'],1062['/foo/bar/baz', '/bar', '/bar'],1063['/foo/bar/baz/', 'quux', '/foo/bar/baz/quux'],1064['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],1065['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'],1066['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'],1067['foo/bar', '../../../baz', '../../baz'],1068['foo/bar/', '../../../baz', '../baz'],1069['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'],1070['http://example.com/b//c//d;p?q#blarg',1071'https:/p/a/t/h?s#hash2',1072'https://p/a/t/h?s#hash2'],1073['http://example.com/b//c//d;p?q#blarg',1074'https://u:[email protected]/p/a/t/h?s#hash2',1075'https://u:[email protected]/p/a/t/h?s#hash2'],1076['http://example.com/b//c//d;p?q#blarg',1077'https:/a/b/c/d',1078'https://a/b/c/d'],1079['http://example.com/b//c//d;p?q#blarg',1080'http:#hash2',1081'http://example.com/b//c//d;p?q#hash2'],1082['http://example.com/b//c//d;p?q#blarg',1083'http:/p/a/t/h?s#hash2',1084'http://example.com/p/a/t/h?s#hash2'],1085['http://example.com/b//c//d;p?q#blarg',1086'http://u:[email protected]/p/a/t/h?s#hash2',1087'http://u:[email protected]/p/a/t/h?s#hash2'],1088['http://example.com/b//c//d;p?q#blarg',1089'http:/a/b/c/d',1090'http://example.com/a/b/c/d'],1091['/foo/bar/baz', '/../etc/passwd', '/etc/passwd']1092];1093relativeTests.forEach(function(relativeTest) {1094var a = url.resolve(relativeTest[0], relativeTest[1]),1095e = relativeTest[2];1096assert.equal(a, e,1097'resolve(' + [relativeTest[0], relativeTest[1]] + ') == ' + e +1098'\n actual=' + a);1099});110011011102// https://github.com/joyent/node/issues/5681103[1104undefined,1105null,1106true,1107false,11080.0,11090,1110[],1111{}1112].forEach(function(val) {1113assert.throws(function() { url.parse(val); }, TypeError);1114});111511161117//1118// Tests below taken from Chiron1119// http://code.google.com/p/chironjs/source/browse/trunk/src/test/http/url.js1120//1121// Copyright (c) 2002-2008 Kris Kowal <http://cixar.com/~kris.kowal>1122// used with permission under MIT License1123//1124// Changes marked with @isaacs11251126var bases = [1127'http://a/b/c/d;p?q',1128'http://a/b/c/d;p?q=1/2',1129'http://a/b/c/d;p=1/2?q',1130'fred:///s//a/b/c',1131'http:///s//a/b/c'1132];11331134//[to, from, result]1135var relativeTests2 = [1136// http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html1137['../c', 'foo:a/b', 'foo:c'],1138['foo:.', 'foo:a', 'foo:'],1139['/foo/../../../bar', 'zz:abc', 'zz:/bar'],1140['/foo/../bar', 'zz:abc', 'zz:/bar'],1141// @isaacs Disagree. Not how web browsers resolve this.1142['foo/../../../bar', 'zz:abc', 'zz:bar'],1143// ['foo/../../../bar', 'zz:abc', 'zz:../../bar'], // @isaacs Added1144['foo/../bar', 'zz:abc', 'zz:bar'],1145['zz:.', 'zz:abc', 'zz:'],1146['/.', bases[0], 'http://a/'],1147['/.foo', bases[0], 'http://a/.foo'],1148['.foo', bases[0], 'http://a/b/c/.foo'],11491150// http://gbiv.com/protocols/uri/test/rel_examples1.html1151// examples from RFC 23961152['g:h', bases[0], 'g:h'],1153['g', bases[0], 'http://a/b/c/g'],1154['./g', bases[0], 'http://a/b/c/g'],1155['g/', bases[0], 'http://a/b/c/g/'],1156['/g', bases[0], 'http://a/g'],1157['//g', bases[0], 'http://g/'],1158// changed with RFC 2396bis1159//('?y', bases[0], 'http://a/b/c/d;p?y'],1160['?y', bases[0], 'http://a/b/c/d;p?y'],1161['g?y', bases[0], 'http://a/b/c/g?y'],1162// changed with RFC 2396bis1163//('#s', bases[0], CURRENT_DOC_URI + '#s'],1164['#s', bases[0], 'http://a/b/c/d;p?q#s'],1165['g#s', bases[0], 'http://a/b/c/g#s'],1166['g?y#s', bases[0], 'http://a/b/c/g?y#s'],1167[';x', bases[0], 'http://a/b/c/;x'],1168['g;x', bases[0], 'http://a/b/c/g;x'],1169['g;x?y#s', bases[0], 'http://a/b/c/g;x?y#s'],1170// changed with RFC 2396bis1171//('', bases[0], CURRENT_DOC_URI],1172['', bases[0], 'http://a/b/c/d;p?q'],1173['.', bases[0], 'http://a/b/c/'],1174['./', bases[0], 'http://a/b/c/'],1175['..', bases[0], 'http://a/b/'],1176['../', bases[0], 'http://a/b/'],1177['../g', bases[0], 'http://a/b/g'],1178['../..', bases[0], 'http://a/'],1179['../../', bases[0], 'http://a/'],1180['../../g', bases[0], 'http://a/g'],1181['../../../g', bases[0], ('http://a/../g', 'http://a/g')],1182['../../../../g', bases[0], ('http://a/../../g', 'http://a/g')],1183// changed with RFC 2396bis1184//('/./g', bases[0], 'http://a/./g'],1185['/./g', bases[0], 'http://a/g'],1186// changed with RFC 2396bis1187//('/../g', bases[0], 'http://a/../g'],1188['/../g', bases[0], 'http://a/g'],1189['g.', bases[0], 'http://a/b/c/g.'],1190['.g', bases[0], 'http://a/b/c/.g'],1191['g..', bases[0], 'http://a/b/c/g..'],1192['..g', bases[0], 'http://a/b/c/..g'],1193['./../g', bases[0], 'http://a/b/g'],1194['./g/.', bases[0], 'http://a/b/c/g/'],1195['g/./h', bases[0], 'http://a/b/c/g/h'],1196['g/../h', bases[0], 'http://a/b/c/h'],1197['g;x=1/./y', bases[0], 'http://a/b/c/g;x=1/y'],1198['g;x=1/../y', bases[0], 'http://a/b/c/y'],1199['g?y/./x', bases[0], 'http://a/b/c/g?y/./x'],1200['g?y/../x', bases[0], 'http://a/b/c/g?y/../x'],1201['g#s/./x', bases[0], 'http://a/b/c/g#s/./x'],1202['g#s/../x', bases[0], 'http://a/b/c/g#s/../x'],1203['http:g', bases[0], ('http:g', 'http://a/b/c/g')],1204['http:', bases[0], ('http:', bases[0])],1205// not sure where this one originated1206['/a/b/c/./../../g', bases[0], 'http://a/a/g'],12071208// http://gbiv.com/protocols/uri/test/rel_examples2.html1209// slashes in base URI's query args1210['g', bases[1], 'http://a/b/c/g'],1211['./g', bases[1], 'http://a/b/c/g'],1212['g/', bases[1], 'http://a/b/c/g/'],1213['/g', bases[1], 'http://a/g'],1214['//g', bases[1], 'http://g/'],1215// changed in RFC 2396bis1216//('?y', bases[1], 'http://a/b/c/?y'],1217['?y', bases[1], 'http://a/b/c/d;p?y'],1218['g?y', bases[1], 'http://a/b/c/g?y'],1219['g?y/./x', bases[1], 'http://a/b/c/g?y/./x'],1220['g?y/../x', bases[1], 'http://a/b/c/g?y/../x'],1221['g#s', bases[1], 'http://a/b/c/g#s'],1222['g#s/./x', bases[1], 'http://a/b/c/g#s/./x'],1223['g#s/../x', bases[1], 'http://a/b/c/g#s/../x'],1224['./', bases[1], 'http://a/b/c/'],1225['../', bases[1], 'http://a/b/'],1226['../g', bases[1], 'http://a/b/g'],1227['../../', bases[1], 'http://a/'],1228['../../g', bases[1], 'http://a/g'],12291230// http://gbiv.com/protocols/uri/test/rel_examples3.html1231// slashes in path params1232// all of these changed in RFC 2396bis1233['g', bases[2], 'http://a/b/c/d;p=1/g'],1234['./g', bases[2], 'http://a/b/c/d;p=1/g'],1235['g/', bases[2], 'http://a/b/c/d;p=1/g/'],1236['g?y', bases[2], 'http://a/b/c/d;p=1/g?y'],1237[';x', bases[2], 'http://a/b/c/d;p=1/;x'],1238['g;x', bases[2], 'http://a/b/c/d;p=1/g;x'],1239['g;x=1/./y', bases[2], 'http://a/b/c/d;p=1/g;x=1/y'],1240['g;x=1/../y', bases[2], 'http://a/b/c/d;p=1/y'],1241['./', bases[2], 'http://a/b/c/d;p=1/'],1242['../', bases[2], 'http://a/b/c/'],1243['../g', bases[2], 'http://a/b/c/g'],1244['../../', bases[2], 'http://a/b/'],1245['../../g', bases[2], 'http://a/b/g'],12461247// http://gbiv.com/protocols/uri/test/rel_examples4.html1248// double and triple slash, unknown scheme1249['g:h', bases[3], 'g:h'],1250['g', bases[3], 'fred:///s//a/b/g'],1251['./g', bases[3], 'fred:///s//a/b/g'],1252['g/', bases[3], 'fred:///s//a/b/g/'],1253['/g', bases[3], 'fred:///g'], // may change to fred:///s//a/g1254['//g', bases[3], 'fred://g'], // may change to fred:///s//g1255['//g/x', bases[3], 'fred://g/x'], // may change to fred:///s//g/x1256['///g', bases[3], 'fred:///g'],1257['./', bases[3], 'fred:///s//a/b/'],1258['../', bases[3], 'fred:///s//a/'],1259['../g', bases[3], 'fred:///s//a/g'],12601261['../../', bases[3], 'fred:///s//'],1262['../../g', bases[3], 'fred:///s//g'],1263['../../../g', bases[3], 'fred:///s/g'],1264// may change to fred:///s//a/../../../g1265['../../../../g', bases[3], 'fred:///g'],12661267// http://gbiv.com/protocols/uri/test/rel_examples5.html1268// double and triple slash, well-known scheme1269['g:h', bases[4], 'g:h'],1270['g', bases[4], 'http:///s//a/b/g'],1271['./g', bases[4], 'http:///s//a/b/g'],1272['g/', bases[4], 'http:///s//a/b/g/'],1273['/g', bases[4], 'http:///g'], // may change to http:///s//a/g1274['//g', bases[4], 'http://g/'], // may change to http:///s//g1275['//g/x', bases[4], 'http://g/x'], // may change to http:///s//g/x1276['///g', bases[4], 'http:///g'],1277['./', bases[4], 'http:///s//a/b/'],1278['../', bases[4], 'http:///s//a/'],1279['../g', bases[4], 'http:///s//a/g'],1280['../../', bases[4], 'http:///s//'],1281['../../g', bases[4], 'http:///s//g'],1282// may change to http:///s//a/../../g1283['../../../g', bases[4], 'http:///s/g'],1284// may change to http:///s//a/../../../g1285['../../../../g', bases[4], 'http:///g'],12861287// from Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py1288['bar:abc', 'foo:xyz', 'bar:abc'],1289['../abc', 'http://example/x/y/z', 'http://example/x/abc'],1290['http://example/x/abc', 'http://example2/x/y/z', 'http://example/x/abc'],1291['../r', 'http://ex/x/y/z', 'http://ex/x/r'],1292['q/r', 'http://ex/x/y', 'http://ex/x/q/r'],1293['q/r#s', 'http://ex/x/y', 'http://ex/x/q/r#s'],1294['q/r#s/t', 'http://ex/x/y', 'http://ex/x/q/r#s/t'],1295['ftp://ex/x/q/r', 'http://ex/x/y', 'ftp://ex/x/q/r'],1296['', 'http://ex/x/y', 'http://ex/x/y'],1297['', 'http://ex/x/y/', 'http://ex/x/y/'],1298['', 'http://ex/x/y/pdq', 'http://ex/x/y/pdq'],1299['z/', 'http://ex/x/y/', 'http://ex/x/y/z/'],1300['#Animal',1301'file:/swap/test/animal.rdf',1302'file:/swap/test/animal.rdf#Animal'],1303['../abc', 'file:/e/x/y/z', 'file:/e/x/abc'],1304['/example/x/abc', 'file:/example2/x/y/z', 'file:/example/x/abc'],1305['../r', 'file:/ex/x/y/z', 'file:/ex/x/r'],1306['/r', 'file:/ex/x/y/z', 'file:/r'],1307['q/r', 'file:/ex/x/y', 'file:/ex/x/q/r'],1308['q/r#s', 'file:/ex/x/y', 'file:/ex/x/q/r#s'],1309['q/r#', 'file:/ex/x/y', 'file:/ex/x/q/r#'],1310['q/r#s/t', 'file:/ex/x/y', 'file:/ex/x/q/r#s/t'],1311['ftp://ex/x/q/r', 'file:/ex/x/y', 'ftp://ex/x/q/r'],1312['', 'file:/ex/x/y', 'file:/ex/x/y'],1313['', 'file:/ex/x/y/', 'file:/ex/x/y/'],1314['', 'file:/ex/x/y/pdq', 'file:/ex/x/y/pdq'],1315['z/', 'file:/ex/x/y/', 'file:/ex/x/y/z/'],1316['file://meetings.example.com/cal#m1',1317'file:/devel/WWW/2000/10/swap/test/reluri-1.n3',1318'file://meetings.example.com/cal#m1'],1319['file://meetings.example.com/cal#m1',1320'file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3',1321'file://meetings.example.com/cal#m1'],1322['./#blort', 'file:/some/dir/foo', 'file:/some/dir/#blort'],1323['./#', 'file:/some/dir/foo', 'file:/some/dir/#'],1324// Ryan Lee1325['./', 'http://example/x/abc.efg', 'http://example/x/'],132613271328// Graham Klyne's tests1329// http://www.ninebynine.org/Software/HaskellUtils/Network/UriTest.xls1330// 01-31 are from Connelly's cases13311332// 32-491333['./q:r', 'http://ex/x/y', 'http://ex/x/q:r'],1334['./p=q:r', 'http://ex/x/y', 'http://ex/x/p=q:r'],1335['?pp/rr', 'http://ex/x/y?pp/qq', 'http://ex/x/y?pp/rr'],1336['y/z', 'http://ex/x/y?pp/qq', 'http://ex/x/y/z'],1337['local/[email protected]#frag',1338'mailto:local',1339'mailto:local/[email protected]#frag'],1340['more/[email protected]#frag',1341'mailto:local/[email protected]',1342'mailto:local/more/[email protected]#frag'],1343['y?q', 'http://ex/x/y?q', 'http://ex/x/y?q'],1344['/x/y?q', 'http://ex?p', 'http://ex/x/y?q'],1345['c/d', 'foo:a/b', 'foo:a/c/d'],1346['/c/d', 'foo:a/b', 'foo:/c/d'],1347['', 'foo:a/b?c#d', 'foo:a/b?c'],1348['b/c', 'foo:a', 'foo:b/c'],1349['../b/c', 'foo:/a/y/z', 'foo:/a/b/c'],1350['./b/c', 'foo:a', 'foo:b/c'],1351['/./b/c', 'foo:a', 'foo:/b/c'],1352['../../d', 'foo://a//b/c', 'foo://a/d'],1353['.', 'foo:a', 'foo:'],1354['..', 'foo:a', 'foo:'],13551356// 50-57[cf. TimBL comments --1357// http://lists.w3.org/Archives/Public/uri/2003Feb/0028.html,1358// http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html)1359['abc', 'http://example/x/y%2Fz', 'http://example/x/abc'],1360['../../x%2Fabc', 'http://example/a/x/y/z', 'http://example/a/x%2Fabc'],1361['../x%2Fabc', 'http://example/a/x/y%2Fz', 'http://example/a/x%2Fabc'],1362['abc', 'http://example/x%2Fy/z', 'http://example/x%2Fy/abc'],1363['q%3Ar', 'http://ex/x/y', 'http://ex/x/q%3Ar'],1364['/x%2Fabc', 'http://example/x/y%2Fz', 'http://example/x%2Fabc'],1365['/x%2Fabc', 'http://example/x/y/z', 'http://example/x%2Fabc'],1366['/x%2Fabc', 'http://example/x/y%2Fz', 'http://example/x%2Fabc'],13671368// 70-771369['local2@domain2', 'mailto:local1@domain1?query1', 'mailto:local2@domain2'],1370['local2@domain2?query2',1371'mailto:local1@domain1',1372'mailto:local2@domain2?query2'],1373['local2@domain2?query2',1374'mailto:local1@domain1?query1',1375'mailto:local2@domain2?query2'],1376['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'],1377['local@domain?query2', 'mailto:?query1', 'mailto:local@domain?query2'],1378['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'],1379['http://example/a/b?c/../d', 'foo:bar', 'http://example/a/b?c/../d'],1380['http://example/a/b#c/../d', 'foo:bar', 'http://example/a/b#c/../d'],13811382// 82-881383// @isaacs Disagree. Not how browsers do it.1384// ['http:this', 'http://example.org/base/uri', 'http:this'],1385// @isaacs Added1386['http:this', 'http://example.org/base/uri', 'http://example.org/base/this'],1387['http:this', 'http:base', 'http:this'],1388['.//g', 'f:/a', 'f://g'],1389['b/c//d/e', 'f://example.org/base/a', 'f://example.org/base/b/c//d/e'],1390['[email protected]/[email protected]',1391'mid:[email protected]/[email protected]',1392'mid:[email protected]/[email protected]/[email protected]'],1393['mini1.xml',1394'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/',1395'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml'],1396['../b/c', 'foo:a/y/z', 'foo:a/b/c'],13971398//changeing auth1399['http://diff:[email protected]',1400'http://asdf:[email protected]',1401'http://diff:[email protected]/']1402];1403relativeTests2.forEach(function(relativeTest) {1404var a = url.resolve(relativeTest[1], relativeTest[0]),1405e = relativeTest[2];1406assert.equal(a, e,1407'resolve(' + [relativeTest[1], relativeTest[0]] + ') == ' + e +1408'\n actual=' + a);1409});14101411//if format and parse are inverse operations then1412//resolveObject(parse(x), y) == parse(resolve(x, y))14131414//host and hostname are special, in this case a '' value is important1415var emptyIsImportant = {'host': true, 'hostname': ''};14161417//format: [from, path, expected]1418relativeTests.forEach(function(relativeTest) {1419var actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]),1420expected = url.parse(relativeTest[2]);142114221423assert.deepEqual(actual, expected);14241425expected = relativeTest[2];1426actual = url.format(actual);14271428assert.equal(actual, expected,1429'format(' + actual + ') == ' + expected + '\nactual:' + actual);1430});14311432//format: [to, from, result]1433// the test: ['.//g', 'f:/a', 'f://g'] is a fundimental problem1434// url.parse('f:/a') does not have a host1435// url.resolve('f:/a', './/g') does not have a host becuase you have moved1436// down to the g directory. i.e. f: //g, however when this url is parsed1437// f:// will indicate that the host is g which is not the case.1438// it is unclear to me how to keep this information from being lost1439// it may be that a pathname of ////g should colapse to /g but this seems1440// to be a lot of work for an edge case. Right now I remove the test1441if (relativeTests2[181][0] === './/g' &&1442relativeTests2[181][1] === 'f:/a' &&1443relativeTests2[181][2] === 'f://g') {1444relativeTests2.splice(181, 1);1445}1446relativeTests2.forEach(function(relativeTest) {1447var actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]),1448expected = url.parse(relativeTest[2]);14491450assert.deepEqual(actual, expected);14511452var expected = relativeTest[2],1453actual = url.format(actual);14541455assert.equal(actual, expected,1456'format(' + relativeTest[1] + ') == ' + expected +1457'\nactual:' + actual);1458});14591460});146114621463