JAVASCRIPT 22
Test.js Guest on 4th May 2021 07:58:18 AM
  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.  
  22. var assert = require('assert');
  23.  
  24. var url = require('./url');
  25.  
  26. // URLs to parse, and expected data
  27. // { url : parsed }
  28. var 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/'Ŗ˛.com/' : {
  501.     'hr//www.xn--wgv71a119e.com/',
  502. 19e.com/',
  503.     'protocol': 'http:',
  504.     'slashes': true,
  505.     'host': 'www.xn--wgv71a119e.com',
  506.     'hostname': 'www.xn--wgv71a119e.com',
  507.     'pathname': '/',
  508.     'path': '/'
  509.   }//example.BĆ¼cher.com/' : {
  510. er.com/' : {
  511.     '//example.xn--bcher-kva.com/',
  512. r-kva.com/',
  513.     'protocol': 'slashes'    'slashes'host'e,
  514.     'host': 'example.xn--bcher-kva.com',
  515.     'hostname': 'example.xn--bcher-kva.com',
  516.     'pathname': '/',
  517.     'path': '/'
  518.  //www.Ć„ffchen.com/' : {
  519. fchen.com/' : {
  520.   //www.xn--ffchen-9ta.com/',
  521. chen-9ta.com/': '   'protocol'slashes'',
  522.     'slashes': true,
  523.     'host': 'www.xn--ffchen-9ta.com': '   'hostname': 'www.xn--ffchen-9ta.com': '   'pathname': '/',
  524.     'path': '///www.Ć„ffchen.cOm;A/b/c?d=e#f g<h>i' : {
  525. c?d=e#f g<h>i' : {//www.xn--ffchen-9ta.com/;A/b/c?d=e#f%20g%3Ch%3Ei',
  526. =e#f%20g%3Ch%3Ei'http:''protocol': 'http:',
  527.     'slashes': true,
  528.     'host': 'www.xn--ffchen-9ta.com'www.xn--ffchen-9ta.com'xn--ffchen-9ta.com';A/b/c'pathname': ';A/b/c',
  529.     'search': '?d=e',
  530.     'query': 'd=e',
  531.     'hash': '#f%20g%3Ch%3Ei',
  532.     '
  533.  },
  534.  
  535.  '/b/c?//SƉLIER.COM/' : {
  536. /SƉLIER.COM/' //xn--slier-bsa.com/',
  537. /xn--slier-bsa.com/',
  538.     'protocol': 'http:',
  539.     'slashes': true,
  540.     'host': 'xn--slier-bsa.com',
  541.     'hostname': 'xn--slier-bsa.com',
  542.     'pathname'
  543.  },
  544.  
  545.  ' 'pat//Ł„ŁŠŁ‡Ł…Ų§ŲØŲŖŁƒŁ„Ł…ŁˆŲ´Ų¹Ų±ŲØŁŠŲŸ.ŁŠŲŸ/' : {
  546. ØŲŖŁƒŁ„Ł//xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f/',
  547.  : {
  548.     'href': 'http://xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f/',
  549.     'protocol': 'http:',
  550.     'slashes'hostname'   'host': 'xn--egbpdaj6bu4bxfgehfvwxn.xn--egb9f',
  551.     ': 'tname': 'path'gbpdaj6bu4bxfgehfvwx//ā˛�.ws/ā˛�' : {
  552. 'pathname': '/',
  553.  //xn--hgi.ws/ā˛�',
  554.  
  555.  
  556.   'protocol'˛�.ws/ā˛�' : {
  557.     'href': 'http://xn--hgi.ws/ā˛�',
  558.     'protocol': 'http:',
  559.    'slashes': true,
  560.     'host': ': '-hgi.ws',
  561.     'http://bucket_name.s3.amazonaws.com/image.jpg'�',
  562.     'path': '/ā˛�'
  563.   },
  564.  
  565.   'http://bucket_name.s3.amazonaws.com/image.jpg': {
  566.     protocol: 'http:',
  567.     'slashes': true,
  568.     slashes: true,
  569.     host: 'bucket_name.s3.amazonaws.com',
  570.     h//bucket_name.s3.amazonaws.com/image.jpg',
  571.   pathname: '/image.jpg',
  572.     href: 'http:///github.com/joyent/node.git': {
  573. ge.jpg',
  574.     'path': '/image.jpg'
  575.   },
  576.  
  577.   'git+http://github.com/joyent/node.git': {
  578.     protocol: 'git+http:',
  579.     slashes: true,
  580.     host: 'github.com',
  581.     hostname: 'github.com',//github.com/joyent/node.git'
  582. it',
  583.    //if local1@domain1 is uses as a relative URL it may
  584. ub//be parse into auth@hostname, but here there is no
  585.  u//way to make it work in url.parse, I add the test to be explicit
  586. here there is no
  587.   //way to make it work in url.parse, I add the test to be explicit
  588.   'local1@domain1': {
  589.     'pathname': //While this may seem counter-intuitive, a browser will parse
  590. oc//<a href='www.google.com'> as a path.
  591. eem counter-intuitive, a browser will parse
  592.   //<a href='www.google.com'www.example.com'www.example.com' : {
  593.     'href'
  594.  },
  595.  
  596.  // ipv6 support
  597.  'thname': ': {
  598.    'le.com',
  599.     'path': 'www.example.com'
  600.   },
  601.  
  602.   // ipv6 support
  603.   '[fe80::1]': {
  604.     'hr//[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]': {
  605.    'path': '[fe80::1]'
  606.   },
  607.  
  608.   'coap://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]': {
  609.     'protocol': 'coap:'hostname'ashes': true,
  610.     'host': '[fedc:ba98:7654:3210:fedc:ba98:7654://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/',
  611. dc:ba98:7654:3210',
  612.     'href': 'coap://[fedc:ba98://[1080:0:0:0:8:800:200C:417A]:61616/': {
  613. hname': '/',
  614.     'path',
  615.    ' },
  616.  
  617.   ': true,
  618.    '0:0:0:8:800:200C:417A]:61616/': {
  619.     'protocol': 'coap:',
  620.     ',
  621.    '': true,
  622.     'host': '[1080:0:0:0:8:800:200c:417a]:61616',
  623. //[1080:0:0:0:8:800:200c:417a]:61616/',
  624. 80:0:0:0:8:800:200c:417a',
  625.     'href': 'coap://[108//user:password@[3ffe:2a00:100:7031::1]:8080': {
  626.  '/',
  627.     'path': '/'
  628.   },
  629.  
  630.   'http://user:password@[3ffe:2a00:100:7031::1]:8080': {
  631.     'protocol': 'http:',
  632.     'slashes': true,
  633.     'auth': 'hostname'word',
  634.     'host': '[3ffe:2a00:100:7031::1]:8//user:password@[3ffe:2a00:100:7031::1]:8080/',
  635. 2a00:100:7031::1'/'    'href': 'http://user:passwor//u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature': {
  636.  'path': '/'
  637.   },
  638.  
  639.   'coap://u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature': {
  640.     'protocol': 'coap:',
  641.     'slashes': true,
  642.     'auth': 'u:p',
  643.     'host': '[::192.//u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature',
  644. 92.9.5.5',
  645.     'href': 'coap://u:p@[::192.9.5.5]:61616/.well-known/r?n=Temperature',
  646.     'search': '?n=Temperature',
  647.     'query': 'n=Temperature',
  648. // empty port
  649. : 'http://example.com:' 'path': '/.well-known/r?n=Temperature'
  650.   },
  651.  
  652.   // empty port
  653.   'http://example.com:': {
  654.     'example.com'http:',
  655.     'slashes//example.com/',
  656. t': 'pathname'om'/'    'hostname': '
  657.  },
  658.  
  659.  'm',
  660.  //example.com:/a/b.html': {
  661. om/',
  662.     'pathname': ',
  663.    ' 'path': '/'
  664.   },
  665.  
  666.   'http://example.com:/a/b.html': {
  667.     'example.com'http:',
  668.     'slashes//example.com/a/b.html',
  669. mple.com',
  670.     'hostname': 'example.com',
  671.     'href'
  672.  },
  673.  
  674.  'examp//example.com:?a=b': {
  675. pathname': '/a/b.html',
  676.     'path': '/a/b.html'
  677.   },
  678.  
  679.   'http://example.com:?a=b': {
  680.     'example.com'http:',
  681.     'slashes//example.com/?a=b',
  682. 'example.com',
  683.     ',
  684.    'e': 'example.com',
  685.     'href': 'http://example.com/?a=b',
  686.     'search'//example.com:#abc': {
  687. 'a=b'protocol'thname': '/',
  688.     'path': true,
  689.    ',
  690.  
  691.   'http://example.com:#abc': {
  692.     'example.com'http:',
  693.     'slashes//example.com/#abc',
  694. 'example.com'#abc' 'hostname': 'example.com',
  695.     ': 'f'
  696.  },
  697.  
  698.  'examp//[fe80::1]:/a/b?a=b#abc': {
  699. bc',
  700.     'pathname': '/',
  701.     'path': '/'
  702.   },
  703.  
  704.   'host'//[fe80::1]:/a/b?a=b#abc': {
  705.     'protocol': 'http:': '   's//[fe80::1]/a/b?a=b#abc',
  706.  '[fe80::1]': '   'hostname': 'fe80::1',
  707.     'href': 'http://[fe80::1]/a/b?a=b#abc',
  708.     'search': '?a=b',
  709.     'query'http://-lovemonsterz.tumblr.com/rss'thname': '/a/b',
  710.     'path',
  711.    '?a=b'
  712.   },
  713.  
  714.   'http://-lovemonsterz.tumblr.com/rss': {
  715.     'protocol': 'http:',
  716.     'slashes': true,
  717.     'host': '-lov//-lovemonsterz.tumblr.com/rss',
  718. ame': '-lovemonsterz.tumblr.com',
  719.     'href': 'http://-lov//-lovemonsterz.tumblr.com:80/rss': {
  720. me': '/rss',
  721.     'path',
  722.    '',
  723.   },
  724.  
  725.   'http://-lovemonsterz.tumblr.com:80/rss': {
  726.     'protocol': 'http:',
  727.     'slashes': true,
  728.     'port': '80',
  729.     'host': '-lovemo//-lovemonsterz.tumblr.com:80/rss',
  730. ': '-lovemonsterz.tumblr.com'path' 'href': 'http://-lovemo//user:pass@-lovemonsterz.tumblr.com/rss': {
  731. rss',
  732.     'path': '/rss',
  733.   },
  734.  
  735.   'http://user:pass@-lovemonsterz.tumblr.com/rss': '
  736.     'protocol': 'http:',
  737.     'slashes': true,
  738.     'auth': 'user:pass',
  739.     'host': '-lov//user:pass@-lovemonsterz.tumblr.com/rss',
  740. vemonsterz.tumblr.com',
  741.    'href': 'http://user:pass@-lov//user:pass@-lovemonsterz.tumblr.com:80/rss': {
  742. ',
  743.     'path': '/rss',
  744.   },
  745.  
  746.   'http://user:pass@-lovemonsterz.tumblr.com:80/rss': '
  747.     'protocol': 'http:',
  748.     'slashes': true,
  749.     'auth': 'user:pass',
  750.     'port': '80',
  751.     'host': '-lovemo//user:pass@-lovemonsterz.tumblr.com:80/rss',
  752. onsterz.tumblr.com',
  753.     'href': ': 'p://user:pass@-lovemo//_jabber._tcp.google.com/test': {
  754. hname': '/rss': '   'path': '/rss',
  755.   },
  756.  
  757.   'http://_jabber._tcp.google.com/test': {
  758.     'hostname': '_jabber._tcp.google.com'rue,
  759.     'host'http://_jabber._tcp.google.com/test'stname'pathname'r._tcp.google.com',
  760.     'href',
  761.  },
  762.  
  763.  'jabbe//user:pass@_jabber._tcp.google.com/test': {
  764. st',
  765.     'path': '/test',
  766.   },
  767.  
  768.   'http://user:pass@_jabber._tcp.google.com/test': '
  769.     'protocol': 'http:',
  770.    'slashes': true,
  771.     'auth': 'user:pass',
  772.     'host'http://user:pass@_jabber._tcp.google.com/test'_jabber._tcp.google.com',
  773.     'href': 'http://user:pass@_jabbe//_jabber._tcp.google.com:80/test': {
  774. ': '/test',
  775.     'http:' '/test',
  776.   },
  777.  
  778.   'http://_jabber._tcp.google.com:80/test': {
  779.     'protocol': 'http:',
  780.     'slashes'_jabber._tcp.google.com',
  781.     'href': 'http://_jabber._tcp.google.com:80/test'ame': 'pathname'tcp.google.com',
  782.     'href': ',
  783.  },
  784.  
  785.  'ber._//user:pass@_jabber._tcp.google.com:80/test': {
  786. ,
  787.     'path': '/test',
  788.   },
  789.  
  790.   'http://user:pass@_jabber._tcp.google.com:80/test': '
  791.     'protocol': 'http:',
  792.     'slashes': true,
  793.     'hostname'ser:pass',
  794.     'port': '80',
  795.    'host': '_jabb//user:pass@_jabber._tcp.google.com:80/test',
  796. er._tcp.google.com',
  797.     'href': 'http://user:pass@_jabber._//x:1/\' <>"`/{}|\\^~`/': {
  798.  'pathname': '/test',
  799.     'path': '/test',
  800.   },
  801.  
  802.   'http://x:1/\' <>"`/{}|\\^~`/': {
  803.     protocol: 'http:',
  804.     slashes: true,
  805.     host: 'x:1',
  806.     port: '1',
  807.     hostname: 'x',
  808.     pathname: '/%27%20%3C%3E%22%60/%7B%//x:1/%27%20%3C%3E%22%60/%7B%7D%7C/%5E~%60/'
  809. 60/%7B%7D%7C/%//a@b@c/': {
  810.  href: 'http://x:1/%27%20%3C%3E%22%60/%7B%7D%7C/%5E~%60/',
  811.    host: 'p://a@b@c/': {
  812.     protocol: 'http:',
  813.  //a%40b@c/',
  814. rue,
  815.     auth: 'a@b',
  816.     host: 'c',
  817.     hostna//a@b?@c': {
  818. href: 'http://a%40b@c/',
  819.     path: '/',
  820.     pathname: ',
  821.    host: 'ttp://a@b?@c': {
  822.     protocol: 'http:',//a@b/?@c',
  823. : true,
  824.     auth: 'a',
  825.     host: 'b',
  826.     hostname: 'b',
  827.     href: '@c'p://a@b/?@c',
  828.  //a\r" \t\n<\'b:b@c\r\nd/e?f':{
  829. /',
  830.     search: '?@c',
  831.    slashes: true,
  832.    auth: '//a\r" \t\n<\'b:b@c\r\nd/e?f'c'
  833.     protocol: 'http:',
  834.     slashes: true,
  835.     auth: 'a\r" \t\n<\'?f'',
  836.     host: 'f',
  837.     port: null,
  838.     hostname: 'c',
  839.     hash: null,
  840.     search: '?f',//a%0D%22%20%09%0A%3C\'b:b@c/%0D%0Ad/e?f'
  841. ,
  842.     pa// git urls used by npm
  843. ref: 'http://git@github.com:npm/npm': {
  844. %0D%0Ad/e?f'
  845.   },
  846.  
  847.   // git urls used by npm
  848.   'git+ssh://git@github.com:npm/npm': {
  849.     protocol: 'git+ssh:',
  850.     slashes: true,
  851.     auth: 'git',
  852.     host: 'github.com',
  853.     port: null,
  854.     hostname: 'github.com',
  855.     hash: null,
  856.     search: null,
  857.  //git@github.com/:npm/npm'
  858. e: '/:npm/npm',
  859.     path: '/:npm/npm',
  860.     href: 'git+ssh://git@github.com/:npm/npm'
  861.   }
  862.  
  863. };
  864.  
  865. Object.keys(parseTests).forEach(function(u) {
  866.   test('parse(' + u + ')', function() {
  867.     var actual = url.parse(u),
  868.         spaced = url.parse('     \t  ' + u + '\n\t');
  869.         expected = parseTests[u];
  870.  
  871.     Object.keys(actual).forEach(function (i) {
  872.       if (expected[i] === undefined && actual[i] === null) {
  873.         expected[i] = null;
  874.       }
  875.     });
  876.  
  877.     assert.deepEqual(actual, expected);
  878.     assert.deepEqual(spaced, expected);
  879.  
  880.     var expected = parseTests[u].href,
  881.         actual = url.format(parseTests[u]);
  882.  
  883.     assert.equal(actual, expected,
  884.                  'format(' + u + ') == ' + u + '\nactual:' + actual);
  885.   });
  886. });
  887.  
  888. var parseTestsWithQueryString = {
  889.   ',
  890.    'r?baz=quux#frag' : {
  891.     'href': '/foo/bar?baz=quux#frag',
  892.     'hash'pathname',
  893.     'search': '?baz=quux'/foo/bar?baz=quux'     'baz': 'q//example.com' : {
  894. thname': ': 'o/bar//example.com/',
  895. foo/bar?baz=quux'http:'  'http://example.com' : {
  896.     'href': 'http://example.com/',
  897.     'example.com'http:',
  898.     ': {},
  899.    'rue,
  900.     ''ost': 'pathname'om'/'    'hostname': '
  901.  },
  902.  'om',
  903.     'query': {},
  904.     'search': '',
  905.     'pathname': '/',
  906.     'path': '/'
  907.   },
  908.   '/example': {
  909.     protocol: null,
  910.     slashes: null,
  911.     auth: null,
  912.     host: null,
  913.     port: null,
  914.     hostname: null,
  915.     hash: null,
  916.     search: ''
  917.  },
  918.  'ry: {},
  919.     pathname: '/example',
  920.     path: '/example',
  921.     href: '/example'
  922.   },
  923.   '/example?query=value':{
  924.     protocol: null,
  925.     slashes: null,
  926.     auth: null,
  927.     host: null,
  928.     port: null,
  929.     hostname: null,
  930.     hash: null,
  931.     search: '?query=value',
  932.     query: { query: 'value' },
  933.     pathname: '/example',
  934.     path: '/example?query=value',
  935.     href: '/example?query=value' + u + '
  936. Object.keys(parseTestsWithQueryString).forEach(function(u) {
  937.   test('parse(' + u + ')', function() {
  938.     var actual = url.parse(u, true);
  939.     var expected = parseTestsWithQueryString[u];
  940.     for (var i in actual) {
  941.       if (actual[i] === null && expected[i] === undefined) {
  942.         e// some extra formatting tests, just to verify
  943. // that it'll format slightly wonky content to a valid url.
  944. ng tests, just to verify
  945. // //example.com?' : {
  946. ightly wonky conte//example.com/?',
  947.  
  948. var formatTests = {
  949.   'http://example.com?' : {
  950.     'href'example.com'ample.com/?',
  951.     'example.com'http:',
  952.     'slashes': true,
  953.     'host': 'example.com',
  954.     'hostname'://example.com?foo=bar#frag' : {
  955. ',
  956.     'query': {}//example.com/?foo=bar#frag',
  957. http://example.com?foo=bar#frag' : {
  958.     'href': ',
  959.    'example.com/?foo=bar#frag',
  960.     'protocol': ',
  961.    '
  962.     'host': 'example.com'query''hostname': 'example.com',
  963.     '
  964.  },
  965.  'frag'//example.com?foo=@bar#frag' : {
  966. query': 'foo=bar',//example.com/?foo=@bar#frag',
  967. tp://example.com?foo=@bar#frag' : {
  968.     'href': 'http://example.com/?foo=@bar#frag',
  969.     'protocol': ',
  970.    '
  971.     'host': 'example.com',
  972.     ': 'tname': ',
  973.    '.com',
  974.     '/'sh': '#frag',
  975. //example.com?foo=/bar/#frag' : {
  976. ery': 'foo=@bar',
  977. //example.com/?foo=/bar/#frag',
  978. ://example.com?foo=/bar/#frag'host'    'href': 'http://example.com/?foo=/bar/#frag',
  979.     'protocol': ',
  980.    '
  981.     'host': 'example.com',
  982.     'hostname': 'example.com',
  983.     'hash': '#frag',
  984.   //example.com?foo=?bar/#frag' : {
  985. ry': 'foo=/bar/',
  986. //example.com/?foo=?bar/#frag',
  987. ://example.com?foo=?bar/#frag'host'    'href': 'http://example.com/?foo=?bar/#frag',
  988.     'protocol': ',
  989.    '
  990.     'host': 'example.com',
  991.     'hostname': 'example.com',
  992.     'hash': '#frag',
  993.   //example.com#frag=?bar/#frag' : {
  994. y': 'href'bar/',
  995.  //example.com/#frag=?bar/#frag',
  996. /example.com#frag=?bar/#frag' : {
  997.     'href': 'http://example.com/#frag=?bar/#frag',
  998.     'protocol': 'http:',
  999.     'host'pathname'e.com',
  1000.     'hostna//google.com" onload="alert(42)/' : {
  1001. =?bar/#frag',
  1002.     //google.com/%22%20onload=%22alert(42)/',
  1003.  onload="alert(42)/' : {
  1004.     'host': 'google.com'le.com/%22%20onload=%22alert(42)/',
  1005.     'protocol': 'http:',
  1006. //a.com/a/b/c?s#h' : {
  1007. ',
  1008.     'pathname'://a.com/a/b/c?s#h',
  1009. lert(42)/'
  1010.   },
  1011.   'http://a.com/a/b/c?s#h' : {
  1012.     'href': 'http://a.com/a/b/c?s#h'h'    'protocol': 'http',
  1013.     'host': 'a.com',
  1014.     'pathname' : {
  1015.    '
  1016.     'hash': 'h',
  1017.     'search': 's'
  1018.   },
  1019.   'xmpp:isaacschlueter@jabber.org' : {
  1020.     'href',
  1021.    ':isaacschlueter@jabber.org',
  1022.     'protocol': 'xmpp:',
  1023.     'host': '//atpass:foo%40bar@127.0.0.1/' : {
  1024. ueter',
  1025.     'http://atpass:foo%40bar@127.0.0.1/'p://atpass:foo%40bar@127.0.0.1/' : {
  1026.     'href': 'http://atpass:foo%40bar@127.0.0.1/',
  1027.     'auth': ': 'ass:foo@bar',
  1028.   //atslash%2F%40:%2F%40@foo/' : {
  1029. rotocol': 'http:',//atslash%2F%40:%2F%40@foo/',
  1030. ttp://atslash%2F%40:%2F%40@foo/' : {
  1031.     ': 'f': 'http://atslash%2F%40:%2F%40@foo/',
  1032.     ': 'h'
  1033.  },
  1034.  'h/@:/@',//foo/bar': {
  1035. ': 'foo',
  1036.     'protoc//foo/bar',
  1037. ,
  1038.     'pathname': '/',
  1039.    ' 'svn+ssh://foo/bar': {
  1040.     'href': ': '+ssh://foo/bar',
  1041.     'hostname': 'foo',
  1042.     '//foo/bar': {
  1043. n+ssh:',
  1044.     'pathname'//foo/bar',
  1045.   'slashes': true
  1046.   },
  1047.   'dash-test://foo/bar': {
  1048.     'href': 'dash-test://foo/bar',
  1049.     ': true
  1050.  },
  1051.  '',
  1052.     'protocol': 'dash-test:',
  1053.     'pathname': '/bar',
  1054.     'slashes': true
  1055.   },
  1056.   'dash-test:foo/bar': {
  1057.     'href': 'dash-test:foo/bar',
  1058.     'hos//foo/bar': {
  1059.  
  1060.     'protocol': 'dash//foo/bar',
  1061.  'pathname': ': 'r'
  1062.   },
  1063.   'protocol'//foo/bar': {
  1064.     'href': 'dot.test://foo/bar',
  1065.     'hostname': 'foo',
  1066.     'protocol': 'dot.test:': '   'pathname': '/bar',
  1067.     'slashes'foo'ue
  1068.   },
  1069.   'dot.test:foo/bar': {
  1070.     'href': ': '.test:foo/bar// ipv6 support
  1071. ': 'foo',
  1072.     'protocol': 'dot.test:',
  1073.     'pathname': '/bar'href'
  1074.   // ipv6 support
  1075.   'coap:u:p@[::1]:61616/.well-known/r?n=Temperature'coap:'  'href': 'coap:u:p@[::1]:61616/.well-known/r?n=Temperature',
  1076.     'protocol': ': 'p:',
  1077.     'auth',
  1078.    ',
  1079.     ': 'tname': '::1',
  1080.     'port': '61616',
  1081.     'pathname': '/.well-known/r',
  1082.     'search': 'n=Temperature'
  1083.   },
  1084.   'coap:[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616/s/stopButton': {
  1085.     'href': 'coap:[fedc:ba98:7654:3210:fedc:ba98:7654:3210]:61616/s/stopButton',
  1086.     'protocol': 'coap',
  1087.     'host': '[fedc// encode context-specific delimiters in path and query, but do not touch
  1088. n'// other non-delimiter chars like `%`.
  1089. im// <https://github.com/joyent/node/issues/4082>
  1090. the// `#`,`?` in path
  1091. rs like `%`.
  1092.   // <https://github.com/joyent/node/issues/4082>
  1093.  
  1094.   // `#`,`?` in path
  1095.   '/path/to/%%23%3F+=&.txt?foo=theA1#bar' : {
  1096.     href : '/path/to/%%23%3F+=&.txt?foo=theA1#bar',
  1097.     pathname: '/// `#`,`?` in path + `#` in query
  1098.       foo: 'theA1'
  1099.     },
  1100.     hash: "#bar"
  1101.   },
  1102.  
  1103.   // `#`,`?` in path + `#` in query
  1104.   '/path/to/%%23%3F+=&.txt?foo=the%231#bar' : {
  1105.     href : '/path/to/%%23%3F+=&.txt?foo=the%231#bar',
  1106.     pathname: '/// `?` and `#` in path and search
  1107.       fo//ex.com/foo%3F100%m%23r?abc=the%231?&foo=bar#frag': {
  1108. #` in path and s//ex.com/foo%3F100%m%23r?abc=the%231?&foo=bar#frag',
  1109. oo=bar#frag': {
  1110.     href: 'http://ex.com/foo%3F100%m%23r?abc=the%231?&foo=bar#frag',
  1111.     protocol: 'http:',
  1112.     hostname: 'ex.com',
  1113.     has// `?` and `#` in search only
  1114. the#1?&f//ex.com/fooA100%mBr?abc=the%231?&foo=bar#frag': {
  1115. ?` and `#` in se//ex.com/fooA100%mBr?abc=the%231?&foo=bar#frag',
  1116. 1?&foo=bar#frag': {
  1117.     href: 'http://ex.com/fooA100%mBr?abc=the%231?&foo=bar#frag',
  1118.     protocol: 'http:',
  1119.     hostname: 'ex.com',
  1120.     hash: '#frag',
  1121.     search: '?abc=the#1?&foo=bar',
  1122.     pathname: '/fooA100%mBr',
  1123.   }
  1124. };
  1125.  
  1126. Object.keys(formatTests).forEach(function(u) {
  1127.   test('format(' + u + ')', function() {
  1128.     var expect = formatTests[u].href;
  1129.     delete formatTests[u].href;
  1130.     var actual = url.format(u);
  1131.     var actualObj = url.format(formatTests[u]);
  1132.     assert.equal(actual, expect,
  1133.                  'wonky format(' + u + ') == ' + expect +
  1134.                  '\nactual:' + actual);
  1135.     assert.equal(actualObj, expect,
  1136.                  'wonky format(' + JSON.stringify(formatTests[u]) +
  1137.       /*
  1138.  [from, path, expected]
  1139. */
  1140.                  '\nactual: ' + actualObj);
  1141.   });
  1142. });
  1143.  
  1144. /*
  1145.  [from, path, expected]
  1146. */
  1147. var relativeTests = [
  1148.   ['/foo/bar/baz', 'quux', '/foo/bar/quux'],
  1149.   ['/foo/bar/baz', '],
  1150.  ['df', '/foo/bar/quux/asdf'],
  1151.   ['/foo/bar/baz'],
  1152.  ['/baz', '/foo/bar/quux/baz'],
  1153.   ['/foo/bar/baz', '../quux/baz'/foo/bar/baz/quux',
  1154.   ['/foo/bar/baz', '/bar', '/bar'],
  1155.   ['/foo/bar/baz/', 'quux', '/foo/bar/baz/quux'],
  1156.   ['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'],
  1157.   ['../../../../../../../quux/baz'/../../../quux/baz', '/quux/baz'],
  1158.   ['/foo/bar/baz', '../../../../../../../quux/baz'],
  1159.  ['x/baz', '  ['/foo', '.', '/'],
  1160.   ['/foo', '..', '/'],
  1161.   ['/foo/', '.', '/foo/'],
  1162.   ['/foo/', '..', '/'],
  1163.   ['],
  1164.  ['r', '.', ', 'o/', '  ['/foo/bar'foo/bar''/'../../../baz'ar/', '.', '/foo/bar/'],
  1165.   [', 'o/bar/', '..', '/foo/'],
  1166.   ['foo/ba//example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'],
  1167. az'],
  1168.   [//example.com/b//c//d;p?q#blarg',
  1169. arg'https:/p/a/t/h?s#hash2's:///#hash2'//p/a/t/h?s#hash2'],
  1170. .com/b//c//example.com/b//c//d;p?q#blarg',
  1171. ?s#hash2',//u:p@h.com/p/a/t/h?s#hash2',
  1172. ,
  1173.   ['http//u:p@h.com/p/a/t/h?s#hash2'],
  1174. g',
  1175.    'h//example.com/b//c//d;p?q#blarg',
  1176.  
  1177.    'https://u:p@h.com/p/a/t/h?//a/b/c/d'],
  1178. ['http:////example.com/b//c//d;p?q#blarg',
  1179.  'https:/a/b/c/d',
  1180.    'http//example.com/b//c//d;p?q#hash2'],
  1181. om/b//c////example.com/b//c//d;p?q#blarg',
  1182.  'http://example.com/b//c//d;p?q#hash//example.com/p/a/t/h?s#hash2'],
  1183. /d;p?q#bl//example.com/b//c//d;p?q#blarg',
  1184.    'http://u:p@h.com/p/a/t/h?s#hash2'2'],
  1185.   ['ht//u:p@h.com/p/a/t/h?s#hash2'],
  1186. arg'http://example.com/b//c//d;p?q#blarg'2',
  1187.    'http://u:p@h.com/p/a/t///example.com/a/b/c/d'],
  1188. xample.com/b//c//d;p?q#blarg',
  1189.    ', 'p:/a/b/c/d',
  1190.    'http://example.com/a/b/c/d'],
  1191.   ['/foo/bar/baz', '/../etc/passwd' + [relativeTest[0], relativeTest[1]] + 'h(function(relativeTest) {
  1192.   test('resolve(' + [relativeTest[0], relativeTest[1]] + ')', function() {
  1193.     var a = url.resolve(relativeTest[0], relativeTest[1]),
  1194.         e = relativeTest[2];
  1195.     assert.equal(a, e,
  1196.                  'resolve(' + [relativeTest[0// https://github.com/joyent/node/issues/568
  1197.         '\n  actual=' + a);
  1198.   });
  1199. });
  1200.  
  1201.  
  1202. // https://github.com/joyent/node/issues/568
  1203. [
  1204.   undefined,
  1205.   null,
  1206.   true,
  1207.   false,
  1208.   0.0,
  1209.   0,
  1210.   [],
  1211.   {}
  1212. ].forEach(function(val) {
  1213.   test('parse(' + val + ')', fu//
  1214. // Tests below taken from Chiron
  1215. // http://code.google.com/p/chironjs/source/browse/trunk/src/test/http/url.js
  1216. //
  1217. // Copyright (c) 2002-2008 Kris Kowal <http://cixar.com/~kris.kowal>
  1218. // used with permission under MIT License
  1219. //
  1220. // Changes marked with @isaacs
  1221. s.kowal>
  1222. // used with p//a/b/c/d;p?q',
  1223. MIT Lice//a/b/c/d;p?q=1/2',
  1224. rked wit//a/b/c/d;p=1/2?q',
  1225.  = [
  1226.   '///s//a/b/c',
  1227. ;p?q',
  1228.  ///s//a/b/c'
  1229. c/d;//[to, from, result]
  1230. /b/c/d;p=1/2?q',
  1231.   'fred:// http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html
  1232. ar relativeTests2 = [
  1233.   // http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html
  1234.   ['../c', 'foo:a/b'],
  1235.  ['c'],
  1236.   ['foo:.'zz:abc'a', 'foo:'],
  1237.   [// @isaacs Disagree. Not how web browsers resolve this.
  1238. ar', 'zz:abc', 'zz:/bar'zz:abc' @isaacs Disagr// ['foo/../../../bar',  'zz:abc', 'zz:../../bar'], // @isaacs Added
  1239. ', 'foo/../bar' // ['foo/../../../bar',  'zz:.'c', 'zz:../../bar'], // @isaacs Added
  1240.   ['foo//a/'],
  1241. , 'zz:abc', bases[0], '  ['z//a/.foo'],
  1242. c', 'zz:', bases[0], 'ases[//a/b/c/.foo'],
  1243. ,
  1244.  // http://gbiv.com/protocols/uri/test/rel_examples1.html
  1245. ],// examples from RFC 2396
  1246. // http://gbiv.com/protocols/uri/test/rel_examples1.//a/b/c/g'],
  1247. mples from RFC 2396
  1248.   ['g://a/b/c/g'],
  1249.  'g:h'],
  1250.   ['g', bases[0]//a/b/c/g/'],
  1251. c/g'/g'  ['./g', bases[0]//a/g'],
  1252. /a/b//g', bases[0], 'http://g/'],
  1253. tp// changed with RFC 2396bis
  1254. s[//('?y', bases[0], 'http://a/b/c/d;p?y'],
  1255. tp://g/'],
  1256.   // changed w//a/b/c/d;p?y'],
  1257.  //('?y', bases[0], 'http://a/b/c/g?y'],
  1258. ,
  1259. // changed with RFC 2396bis
  1260. /b//('#s', bases[0], CURRENT_DOC_URI + '#s'],
  1261. c/g?y'],
  1262.   // changed wit//a/b/c/d;p?q#s'],
  1263. '#s'g#s'ses[0], CURRENT_DO//a/b/c/g#s'],
  1264.   ['g?y#s'ases[0], 'http://a//a/b/c/g?y#s'],
  1265.  ['g#s', bases[0], 'http://a/b/c/;x'],
  1266.  
  1267.   ['g?y#s', bases[0], 'ht//a/b/c/g;x'],
  1268. s'],
  1269.   [';x' , bases[0], 'ttp:///a/b/c/g;x?y#s'],
  1270. x'// changed with RFC 2396bis
  1271. x'//('', bases[0], CURRENT_DOC_URI],
  1272. /a/b/c/g;x?y#s'],
  1273.   // //a/b/c/d;p?q'],
  1274. 2396bis
  1275.   //('', bases[0//a/b/c/'],
  1276. OC_URI],
  1277.   ['', bases[0],//a/b/c/'],
  1278. /c/d;p?q'],
  1279.   ['.', bases//a/b/'],
  1280. ://a/b/c/'],
  1281.   ['./', base//a/b/'],
  1282. p://a/b/c/'],
  1283.   ['..', base//a/b/g'],
  1284. ://a/b/'],
  1285.   ['../', bases[0//a/'],
  1286. ://a/b/'],
  1287.   ['../g', bases[0//a/'],
  1288. ://a/b/g'],
  1289.   ['../..', bases[0//a/g'],
  1290. //a/'],
  1291.   ['../../', bases[0], 'ht//a/../g', 'http://a/g')],
  1292. ases[0], 'http://a/g'],
  1293.   ['../../..///a/../../g', 'http://a/g')],
  1294. , // changed with RFC 2396bis
  1295. /.//('/./g', bases[0], 'http://a/./g'],
  1296. http://a/g')],
  1297.   // changed//a/g'],
  1298.  2// changed with RFC 2396bis
  1299. , //('/../g', bases[0], 'http://a/../g'],
  1300. ttp://a/g', bases[0], 'ed wi//a/g'],
  1301. 96bis
  1302.   //('/../g', bases//a/b/c/g.'],
  1303. /../g'],
  1304.   ['/../g', base//a/b/c/.g'],
  1305. a/g'g..' ['g.', bases[0], //a/b/c/g..'],
  1306. .'],
  1307.   ['.g', bases[0], 'h//a/b/c/..g'],
  1308. ],
  1309.   ['g..', bases[0], 'http://a/b/g'],
  1310. '],
  1311.   ['..g', bases[0], 'htt//a/b/c/g/'],
  1312. ],
  1313.   ['./../g', bases[0], 'h//a/b/c/g/h'],
  1314.   ['g/../h' bases[0], 'http:///a/b/c/h'],
  1315.   ['g;x=1/./y'ses[0], 'http://a///a/b/c/g;x=1/y'],
  1316. /h', bases[0], 'http://a/b/c/h'],//a/b/c/y'],
  1317. y', bases[0], 'http://a/b/c/g;//a/b/c/g?y/./x'],
  1318. ../y', bases[0], 'http://a/b/c///a/b/c/g?y/../x'],
  1319. ases[0], 'http://a/b/c/g?y/./x//a/b/c/g#s/./x'],
  1320. bases[0], 'http://a/b/c/g?y/..///a/b/c/g#s/../x'],
  1321. ases[0], 'http://a/b/c/g#s/./x'],
  1322.   ['g#//a/b/c/g')],
  1323. [0], 'http://a/b/c/g#s/../x'],
  1324.   ['http:g', ba// not sure where this one originated
  1325.  
  1326.   ['http:', bases[0], ('http:', bases[//a/a/g'],
  1327. not// http://gbiv.com/protocols/uri/test/rel_examples2.html
  1328. se// slashes in base URI's query args
  1329. gbiv.com/protocols/uri/t//a/b/c/g'],
  1330. les2.html
  1331.   // slashes in //a/b/c/g'],
  1332. ery args
  1333.   ['g', bases[1]//a/b/c/g/'],
  1334. c/g'/g'  ['./g', bases[1]//a/g'],
  1335. /a/b//g', bases[1], 'http://g/'],
  1336. tp// changed in RFC 2396bis
  1337. se//('?y', bases[1], 'http://a/b/c/?y'],
  1338. , 'http://g/'],
  1339.   // chan//a/b/c/d;p?y'],
  1340. s
  1341.   //(', bases[1], ', 'ht//a/b/c/g?y'],
  1342. ,
  1343.   ['?y', bases[1], 'http://a///a/b/c/g?y/./x'],
  1344. y', bases[1], 'http://a/b/c/g?y//a/b/c/g?y/../x'],
  1345. ases[1], 'http://a/b/c/g?y//a/b/c/g#s'],
  1346. /../x', bases[1], 'http://a/b/c//a/b/c/g#s/./x'],
  1347. s', bases[1], 'http://a/b/c/g#s//a/b/c/g#s/../x'],
  1348. ases[1], 'http://a/b/c/g#//a/b/c/'],
  1349. 'g#s/../x', bases[1], 'htt//a/b/'],
  1350. g#s/../x', bases[1], 'ases[//a/b/g'],
  1351. /a/b/c/'],
  1352.   ['../', bases[1]//a/'],
  1353. //a/b/'],
  1354.   ['../g', bases[1], //a/g'],
  1355. /b/// http://gbiv.com/protocols/uri/test/rel_examples3.html
  1356. ba// slashes in path params
  1357. //// all of these changed in RFC 2396bis
  1358. _examples3.html
  1359.   // sla//a/b/c/d;p=1/g'],
  1360.  
  1361.   // all of these changed//a/b/c/d;p=1/g'],
  1362. 'g', bases[2], 'http://a///a/b/c/d;p=1/g/'],
  1363. /g', bases[2], 'http://a/b//a/b/c/d;p=1/g?y'],
  1364. , bases[2], 'http://a/b/c//a/b/c/d;p=1/;x'],
  1365. ', bases[2], 'http://a/b/c//a/b/c/d;p=1/g;x'],
  1366. , bases[2], 'http://a/b/c/d;p=1///a/b/c/d;p=1/g;x=1/y'],
  1367.  'http://a/b/c/d;p=1/g;x'],
  1368.   ['g//a/b/c/d;p=1/y'],
  1369. , 'http://a/b/c/d;p=1/g;x//a/b/c/d;p=1/'],
  1370. ../y', bases[2], 'http://a//a/b/c/'],
  1371. '],
  1372.   ['./', bases[2], 'htt//a/b/c/g'],
  1373. =1/'../../'../', bases[2], 'h//a/b/'],
  1374. c/'],
  1375.   ['../g', bases[2], 'htt//a/b/g'],
  1376. '],// http://gbiv.com/protocols/uri/test/rel_examples4.html
  1377. se// double and triple slash, unknown scheme
  1378. m/protocols/uri/test/rel_examples4.html
  1379.   // double ///s//a/b/g'],
  1380. h, unknown scheme
  1381.   ['g:h'///s//a/b/g'],
  1382. h'],
  1383.   ['g', bases[3], 'f///s//a/b/g/'],
  1384. ],
  1385.   [', bases[3], '], 'f///g'],  // may change to fred:///s//a/g
  1386. ed:///g', bases[3], 'fred://g'],   // may change to fred:///s//g
  1387. e to//g/x', bases[3], 'fred://g/x'], // may change to fred:///s//g/x
  1388. to f///g', bases[3], 'fred:///g'],
  1389. ], './'d://g/x'], // may ///s//a/b/'],
  1390. :///s//g/x
  1391.   ['///g', base///s//a/'],
  1392. ///g'],
  1393.   ['./', bases[3], ///s//a/g'],
  1394. /b/'],
  1395.   ['../', bases[3], 'fr///s//'],
  1396. /'],
  1397.   ['../g', bases[3], 'fred///s//g'],
  1398. ],
  1399.  
  1400.   ['../../', bases[3], 'fred:///s/g'],
  1401.   // may change to fred:///s//a/../../../g
  1402.  ['../../../g', bases[3], 'fred:///s///g'],
  1403. // // http://gbiv.com/protocols/uri/test/rel_examples5.html
  1404.  b// double and triple slash, well-known scheme
  1405. rotocols/uri/test/rel_examples5.html
  1406.   // double and///s//a/b/g'],
  1407. well-known scheme
  1408.   ['g:h'///s//a/b/g'],
  1409. h'],
  1410.   ['g', bases[4], 'h///s//a/b/g/'],
  1411. ],
  1412.   [', bases[4], '], 'h///g'],  // may change to http:///s//a/g
  1413. tp:///g', bases[4], 'http://g/'],   // may change to http:///s//g
  1414.  to //g/x', bases[4], 'http://g/x'], // may change to http:///s//g/x
  1415. to h///g', bases[4], 'http:///g'],
  1416. ], './'p://g/x'], // may ///s//a/b/'],
  1417. :///s//g/x
  1418.   ['///g', base///s//a/'],
  1419. ///g'],
  1420.   ['./', bases[4], ///s//a/g'],
  1421. /b/'../../'../', bases[4], 'h///s//'],
  1422. a/'],
  1423.   ['../g', bases[4], 'htt///s//g'],
  1424. ']// may change to http:///s//a/../../g
  1425. ],
  1426.   ['../../g', bases[4], ''http///s/g'],
  1427. ,
  1428. // may change to http:///s//a/../../../g
  1429.  ['../../../g', bases[4], 'http:///s///g'],
  1430. // // from Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py
  1431. ///g'],
  1432.  
  1433.   // from Dan Connelly's tests in http://www.w3//example/x/y/z', 'http://example/x/abc'],
  1434. 'foo:xyz'//example/x/abc', 'http://example2/x/y/z', 'http://example/x/abc'],
  1435. /abc'],
  1436.   ['http://ex/x/y/z'/abc', '//ex/x/r'],
  1437. le2/x/y/z', 'htt//ex/x/y', 'http://ex/x/q/r'],
  1438.  'http://ex/x/y/z'//ex/x/y', 'http://ex/x/q/r#s'],
  1439. tp://ex/x/y', 'http://ex/x/y', 'http://ex/x/q/r#s/t'],
  1440. x/x/y', //ex/x/q/r', 'http://ex/x/y', 'ftp://ex/x/q/r'],
  1441. y', ', 'p://e//ex/x/y', 'http://ex/x/y'],
  1442. /q/r', 'http://ex/x/y/', 'http://ex/x/y/'],
  1443.  [''' 'http:///ex/x/y/pdq', 'http://ex/x/y/pdq'],
  1444. ttp://ex/x/y/',//ex/x/y/', 'http://ex/x/y/z/'],
  1445. //ex/x/y/pdq', 'http://ex/x/y/pdq'],
  1446.   ['z/', 'http://ex/x/y/', 'http://ex/x/y/z/'],
  1447.   ['#Animal',
  1448.    'file:/swap/test/animal.rdf',
  1449.    'file:/swap/test/animal.rdf#Animal'],
  1450.   ['../abc', 'file:/e/x/y/z', 'file:/e/x/abc'],
  1451.   ['/example/x/abc', 'file:/example2/x/y/z', 'file:/example/x/abc'],
  1452.  ['../r', 'file:/ex/x/y/z'file:/ex/x/q/r''],
  1453.   ['/r', 'file:/ex/x/y/z', 'file:/r'],
  1454.   ['q/r', 'file:/ex/x/y', 'file:/ex/x/q/r'],
  1455.   ['q/r#s', 'file:/ex/x/y'file:/ex/x/y'/q/r#s'],
  1456.   ['q/r#', '],
  1457.  ['x/x///ex/x/q/r', 'file:/ex/x/y', 'ftp://ex/x/q/r'],
  1458. x/y'' 'file:/ex/x/q/r#s/t'],
  1459.   ['ftp://ex/x/q/r'file:/ex/x/y/'y', 'ftp://ex/x/q/r'],
  1460.   [''file:/ex/x/y/pdq' 'file:/ex/x/y'],
  1461.   ['', 'file:/ex/x/y/', 'file:/ex/x/y/'],
  1462.   ['', 'file:/ex/x//meetings.example.com/cal#m1',
  1463. ['z/', 'file:/ex/x/y/', 'file:/ex/x/y/z/'],
  1464.   ['file://meetin//meetings.example.com/cal#m1'],
  1465. /devel/WW//meetings.example.com/cal#m1',
  1466. ,
  1467.    'file://meetings.example.com/cal#m1'],
  1468.   ['file://meetings.example.com///meetings.example.com/cal#m1'],
  1469. w3ccvs/WWW/2000/10/swap/test/reluri-1.n3',
  1470.    'file://meetings.example.com/cal#m1'],
  1471.   ['./#blort', 'file:/some/dir/fo// Ryan Lee
  1472. ome/dir/#blort'//example/x/abc.efg', 'http://example/x/'],
  1473. me/d// Graham Klyne's tests
  1474. ['// http://www.ninebynine.org/Software/HaskellUtils/Network/UriTest.xls
  1475. yn// 01-31 are from Connelly's cases
  1476. e.o// 32-49
  1477. re/HaskellUtils/Ne//ex/x/y', 'http://ex/x/q:r'],
  1478. e from Connelly's ca//ex/x/y', 'http://ex/x/p=q:r'],
  1479. ://ex/x/y', 'http:///ex/x/y?pp/qq', 'http://ex/x/y?pp/rr'],
  1480. ', 'y/z'://ex/x///ex/x/y?pp/qq', 'http://ex/x/y/z'],
  1481. pp/qq', 'http://ex/x/y?pp/rr'],
  1482.   ['y/z', 'http://ex/x/y?pp/qq', 'http://ex/x/y/z'],
  1483.   ['local/qual@domain.org#frag',
  1484.    'mailto:local',
  1485.    'mailto:local/qual@domain.org#frag'],
  1486.   ['more/qual2@domain2.org#frag',
  1487.    'y?q'to:local//ex/x/y?q', 'http://ex/x/y?q'],
  1488. ocal/more/qual2@dom//ex?p', 'http://ex/x/y?q'],
  1489. ttp://ex/x/y?q', 'http://ex/x/y?q'],
  1490.   ['/x/y?q', 'http://ex?p', 'http://ex/x/y?q'],
  1491.   ['c/d'foo:a/b?c'', 'foo:a/c/d'foo:a''/c/d', 'foo:a/b', 'foo:/c/d'],
  1492.   ['', 'foo:a/b?c#d', 'foo:a/b?c'],
  1493.   ['b/c', 'foo:a', 'foo:b/c'],
  1494.   ['foo:a'', 'foo:/a/y/z', 'foo:/a/b/c'],
  1495.   //a//b/c', 'foo://a/d'],
  1496. /c'],
  1497.   ['/./b/c', 'foo:a', 'foo:/b/c'],
  1498.   ['foo:'/d', '// 50-57[cf. TimBL comments --
  1499. ['//  http://lists.w3.org/Archives/Public/uri/2003Feb/0028.html,
  1500. . //  http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html)
  1501. /2003Feb/0028.ht//example/x/y%2Fz', 'http://example/x/abc'],
  1502. /uri/2003Jan/0008.html)
  1503.   //example/a/x/y/z', 'http://example/a/x%2Fabc'],
  1504. /x/abc'],
  1505.   ['../../x%2//example/a/x/y%2Fz', 'http://example/a/x%2Fabc'],
  1506. x%2Fabc', '  ['.//example/x%2Fy/z', 'http://example/x%2Fy/abc'],
  1507. xample/a/x%2Fabc']//ex/x/y', 'http://ex/x/q%3Ar'],
  1508. /z', 'http://example///example/x/y%2Fz', 'http://example/x%2Fabc'],
  1509. ://ex/x/q%3Ar'],
  1510.   ['//example/x/y/z', 'http://example/x%2Fabc'],
  1511. example/x%2Fabc'http://example/x/y%2Fz'://examp//example/x%2Fabc'],
  1512. amp// 70-77
  1513. c'],
  1514.   ['/x%2Fabc', 'http://example/x/y%2Fz', 'http://example/x%2Fabc'],
  1515.  
  1516.   // 70-77
  1517.   ['local2@domain2', 'mailto:local1@domain1?query1', 'mailto:local2@domain2?query2'local2@domain2?query2',
  1518.    'mailto:local1@domain1',
  1519.    'mailto:local2@domain2?query2'],
  1520.   ['local2@domain2?query2', '  'mailto:local1@domain1?query1',
  1521.    'mailto:local2@domain2?query2'],
  1522.   ['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'],
  1523.   ['local@domain?query2', 'mailto:?query1', 'mailto:local@domain?query2'],//example/a/b?c/../d', 'foo:bar', 'http://example/a/b?c/../d'],
  1524. n?query2'//example/a/b#c/../d', 'foo:bar', 'http://example/a/b#c/../d'],
  1525. b?c// 82-88
  1526.   // @isaacs Disagree. Not how browsers do it.
  1527. p:// ['http:this', 'http://example.org/base/uri', 'http:this'],
  1528.  h// @isaacs Added
  1529. .
  1530.   // ['http:this', '//example.org/base/uri', 'http://example.org/base/this'],
  1531. dded
  1532.   ['http:this', 'http://example.org/base/ur//g', 'f:/a', 'f://g'],
  1533. base/th//d/e', 'f://example.org/base/a', 'f://example.org/base/b/c//d/e'],
  1534. 'f://g'],
  1535.   ['b/c//d/e', 'f://example.org/base/a', 'f://example.org/base/b/c//d/e'],
  1536.   ['m2@example.ord/c2@example.org',
  1537.    'mid:m@example.ord/c@example.o///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/',
  1538. e.org'],
  1539. ///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml'],
  1540. 01/examples/',
  1541.    'file:///C:/DEV/Haskell/l//changeing auth
  1542. 01/exampl//diff:auth@www.example.com',
  1543. foo:a/y/z//asdf:qwer@www.example.com',
  1544. g auth
  1545.   //diff:auth@www.example.com/']
  1546. com',
  1547.    'http://asdf:qwer@www.example.com',
  1548.    'http://diff:auth@www.example.com/']
  1549. ];
  1550.  
  1551. relativeTests2.forEach(function(relativeTest) {
  1552.   test('resolve(' + [relativeTest[1], relativeTest[0]] + ')', function() {
  1553.     var a = url.resolve(relativeTest[1], relativeTest[0]),
  1554.         e = relativeTest[2];
  1555.     assert.equal(a, e,
  1556.                  'resolve(' + [relativeTest[//if format and parse are inverse operations then
  1557. //resolveObject(parse(x), y) == parse(resolve(x, y))
  1558. r//host and hostname are special, in this case a '' value is important
  1559. esolve(x, y))
  1560.  
  1561. //host and hostname are special, in this //format: [from, path, expected]
  1562. emptyIsImportant = {'host': true, 'hostname': ''};
  1563.  
  1564. //format: [from, path, expected]
  1565. relativeTests.forEach(function(relativeTest) {
  1566. test('resolveObject(' + [relativeTest[0], relativeTest[1]] + ')', function() {
  1567.     var actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]),
  1568.         expected = url.parse(relativeTest[2]);
  1569.  
  1570.  
  1571.     assert.deepEqual(actual, expected);
  1572.  
  1573.     expected = relativeTest[2];
  1574.     actual = url.format(actual);
  1575.  
  1576.     assert.equal(actual, expected,
  1577.         //format: [to, from, result]
  1578. // the test: ['.//g', 'f:/a', 'f://g'] is a fundamental problem
  1579. // url.parse('f:/a') does not have a host
  1580. // url.resolve('f:/a', './/g') does not have a host because you have moved
  1581. // down to the g directory.  i.e. f:     //g, however when this url is parsed
  1582. // f:// will indicate that the host is g which is not the case.
  1583. // it is unclear to me how to keep this information from being lost
  1584. // it may be that a pathname of ////g should collapse to /g but this seems
  1585. // to be a lot of work for an edge case.  Right now I remove the test
  1586. but this seems
  1587. // to be a lot of //g' &&
  1588.  an edge case.  Right now I remove the test
  1589. if (relativeTests2[181][0] === //g') {
  1590. &
  1591.     relativeTests2[181][1] === 'f:/a' &&
  1592.     relativeTests2[181][2] === 'f://g') {
  1593.   relativeTests2.splice(181, 1);
  1594. }
  1595.  
  1596. relativeTests2.forEach(function(relativeTest) {
  1597.   test('resolveObject(' + [relativeTest[1], relativeTest[0]] + ')', function() {
  1598.     var actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]),
  1599.         expected = url.parse(relativeTest[2]);
  1600.  
  1601.     assert.deepEqual(actual, expected);
  1602.  
  1603.     var expected = relativeTest[2],
  1604.         actual = url.format(actual);
  1605.  
  1606.     assert.equal(actual, expected,
  1607.                  'format(' + rel

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.