11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_cirequire('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst inspect = require('util').inspect; 51cb0ef41Sopenharmony_ciconst url = require('url'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci// When source is false 81cb0ef41Sopenharmony_ciassert.strictEqual(url.resolveObject('', 'foo'), 'foo'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// [from, path, expected] 111cb0ef41Sopenharmony_ciconst relativeTests = [ 121cb0ef41Sopenharmony_ci ['/foo/bar/baz', 'quux', '/foo/bar/quux'], 131cb0ef41Sopenharmony_ci ['/foo/bar/baz', 'quux/asdf', '/foo/bar/quux/asdf'], 141cb0ef41Sopenharmony_ci ['/foo/bar/baz', 'quux/baz', '/foo/bar/quux/baz'], 151cb0ef41Sopenharmony_ci ['/foo/bar/baz', '../quux/baz', '/foo/quux/baz'], 161cb0ef41Sopenharmony_ci ['/foo/bar/baz', '/bar', '/bar'], 171cb0ef41Sopenharmony_ci ['/foo/bar/baz/', 'quux', '/foo/bar/baz/quux'], 181cb0ef41Sopenharmony_ci ['/foo/bar/baz/', 'quux/baz', '/foo/bar/baz/quux/baz'], 191cb0ef41Sopenharmony_ci ['/foo/bar/baz', '../../../../../../../../quux/baz', '/quux/baz'], 201cb0ef41Sopenharmony_ci ['/foo/bar/baz', '../../../../../../../quux/baz', '/quux/baz'], 211cb0ef41Sopenharmony_ci ['/foo', '.', '/'], 221cb0ef41Sopenharmony_ci ['/foo', '..', '/'], 231cb0ef41Sopenharmony_ci ['/foo/', '.', '/foo/'], 241cb0ef41Sopenharmony_ci ['/foo/', '..', '/'], 251cb0ef41Sopenharmony_ci ['/foo/bar', '.', '/foo/'], 261cb0ef41Sopenharmony_ci ['/foo/bar', '..', '/'], 271cb0ef41Sopenharmony_ci ['/foo/bar/', '.', '/foo/bar/'], 281cb0ef41Sopenharmony_ci ['/foo/bar/', '..', '/foo/'], 291cb0ef41Sopenharmony_ci ['foo/bar', '../../../baz', '../../baz'], 301cb0ef41Sopenharmony_ci ['foo/bar/', '../../../baz', '../baz'], 311cb0ef41Sopenharmony_ci ['http://example.com/b//c//d;p?q#blarg', 'https:#hash2', 'https:///#hash2'], 321cb0ef41Sopenharmony_ci ['http://example.com/b//c//d;p?q#blarg', 331cb0ef41Sopenharmony_ci 'https:/p/a/t/h?s#hash2', 341cb0ef41Sopenharmony_ci 'https://p/a/t/h?s#hash2'], 351cb0ef41Sopenharmony_ci ['http://example.com/b//c//d;p?q#blarg', 361cb0ef41Sopenharmony_ci 'https://u:p@h.com/p/a/t/h?s#hash2', 371cb0ef41Sopenharmony_ci 'https://u:p@h.com/p/a/t/h?s#hash2'], 381cb0ef41Sopenharmony_ci ['http://example.com/b//c//d;p?q#blarg', 391cb0ef41Sopenharmony_ci 'https:/a/b/c/d', 401cb0ef41Sopenharmony_ci 'https://a/b/c/d'], 411cb0ef41Sopenharmony_ci ['http://example.com/b//c//d;p?q#blarg', 421cb0ef41Sopenharmony_ci 'http:#hash2', 431cb0ef41Sopenharmony_ci 'http://example.com/b//c//d;p?q#hash2'], 441cb0ef41Sopenharmony_ci ['http://example.com/b//c//d;p?q#blarg', 451cb0ef41Sopenharmony_ci 'http:/p/a/t/h?s#hash2', 461cb0ef41Sopenharmony_ci 'http://example.com/p/a/t/h?s#hash2'], 471cb0ef41Sopenharmony_ci ['http://example.com/b//c//d;p?q#blarg', 481cb0ef41Sopenharmony_ci 'http://u:p@h.com/p/a/t/h?s#hash2', 491cb0ef41Sopenharmony_ci 'http://u:p@h.com/p/a/t/h?s#hash2'], 501cb0ef41Sopenharmony_ci ['http://example.com/b//c//d;p?q#blarg', 511cb0ef41Sopenharmony_ci 'http:/a/b/c/d', 521cb0ef41Sopenharmony_ci 'http://example.com/a/b/c/d'], 531cb0ef41Sopenharmony_ci ['/foo/bar/baz', '/../etc/passwd', '/etc/passwd'], 541cb0ef41Sopenharmony_ci ['http://localhost', 'file:///Users/foo', 'file:///Users/foo'], 551cb0ef41Sopenharmony_ci ['http://localhost', 'file://foo/Users', 'file://foo/Users'], 561cb0ef41Sopenharmony_ci ['https://registry.npmjs.org', '@foo/bar', 'https://registry.npmjs.org/@foo/bar'], 571cb0ef41Sopenharmony_ci]; 581cb0ef41Sopenharmony_cirelativeTests.forEach(function(relativeTest) { 591cb0ef41Sopenharmony_ci const a = url.resolve(relativeTest[0], relativeTest[1]); 601cb0ef41Sopenharmony_ci const e = relativeTest[2]; 611cb0ef41Sopenharmony_ci assert.strictEqual(a, e, 621cb0ef41Sopenharmony_ci `resolve(${relativeTest[0]}, ${relativeTest[1]})` + 631cb0ef41Sopenharmony_ci ` == ${e}\n actual=${a}`); 641cb0ef41Sopenharmony_ci}); 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci// 671cb0ef41Sopenharmony_ci// Tests below taken from Chiron 681cb0ef41Sopenharmony_ci// http://code.google.com/p/chironjs/source/browse/trunk/src/test/http/url.js 691cb0ef41Sopenharmony_ci// 701cb0ef41Sopenharmony_ci// Copyright (c) 2002-2008 Kris Kowal <http://cixar.com/~kris.kowal> 711cb0ef41Sopenharmony_ci// used with permission under MIT License 721cb0ef41Sopenharmony_ci// 731cb0ef41Sopenharmony_ci// Changes marked with @isaacs 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_ciconst bases = [ 761cb0ef41Sopenharmony_ci 'http://a/b/c/d;p?q', 771cb0ef41Sopenharmony_ci 'http://a/b/c/d;p?q=1/2', 781cb0ef41Sopenharmony_ci 'http://a/b/c/d;p=1/2?q', 791cb0ef41Sopenharmony_ci 'fred:///s//a/b/c', 801cb0ef41Sopenharmony_ci 'http:///s//a/b/c', 811cb0ef41Sopenharmony_ci]; 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci// [to, from, result] 841cb0ef41Sopenharmony_ciconst relativeTests2 = [ 851cb0ef41Sopenharmony_ci // http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html 861cb0ef41Sopenharmony_ci ['../c', 'foo:a/b', 'foo:c'], 871cb0ef41Sopenharmony_ci ['foo:.', 'foo:a', 'foo:'], 881cb0ef41Sopenharmony_ci ['/foo/../../../bar', 'zz:abc', 'zz:/bar'], 891cb0ef41Sopenharmony_ci ['/foo/../bar', 'zz:abc', 'zz:/bar'], 901cb0ef41Sopenharmony_ci // @isaacs Disagree. Not how web browsers resolve this. 911cb0ef41Sopenharmony_ci ['foo/../../../bar', 'zz:abc', 'zz:bar'], 921cb0ef41Sopenharmony_ci // ['foo/../../../bar', 'zz:abc', 'zz:../../bar'], // @isaacs Added 931cb0ef41Sopenharmony_ci ['foo/../bar', 'zz:abc', 'zz:bar'], 941cb0ef41Sopenharmony_ci ['zz:.', 'zz:abc', 'zz:'], 951cb0ef41Sopenharmony_ci ['/.', bases[0], 'http://a/'], 961cb0ef41Sopenharmony_ci ['/.foo', bases[0], 'http://a/.foo'], 971cb0ef41Sopenharmony_ci ['.foo', bases[0], 'http://a/b/c/.foo'], 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ci // http://gbiv.com/protocols/uri/test/rel_examples1.html 1001cb0ef41Sopenharmony_ci // examples from RFC 2396 1011cb0ef41Sopenharmony_ci ['g:h', bases[0], 'g:h'], 1021cb0ef41Sopenharmony_ci ['g', bases[0], 'http://a/b/c/g'], 1031cb0ef41Sopenharmony_ci ['./g', bases[0], 'http://a/b/c/g'], 1041cb0ef41Sopenharmony_ci ['g/', bases[0], 'http://a/b/c/g/'], 1051cb0ef41Sopenharmony_ci ['/g', bases[0], 'http://a/g'], 1061cb0ef41Sopenharmony_ci ['//g', bases[0], 'http://g/'], 1071cb0ef41Sopenharmony_ci // Changed with RFC 2396bis 1081cb0ef41Sopenharmony_ci // ('?y', bases[0], 'http://a/b/c/d;p?y'], 1091cb0ef41Sopenharmony_ci ['?y', bases[0], 'http://a/b/c/d;p?y'], 1101cb0ef41Sopenharmony_ci ['g?y', bases[0], 'http://a/b/c/g?y'], 1111cb0ef41Sopenharmony_ci // Changed with RFC 2396bis 1121cb0ef41Sopenharmony_ci // ('#s', bases[0], CURRENT_DOC_URI + '#s'], 1131cb0ef41Sopenharmony_ci ['#s', bases[0], 'http://a/b/c/d;p?q#s'], 1141cb0ef41Sopenharmony_ci ['g#s', bases[0], 'http://a/b/c/g#s'], 1151cb0ef41Sopenharmony_ci ['g?y#s', bases[0], 'http://a/b/c/g?y#s'], 1161cb0ef41Sopenharmony_ci [';x', bases[0], 'http://a/b/c/;x'], 1171cb0ef41Sopenharmony_ci ['g;x', bases[0], 'http://a/b/c/g;x'], 1181cb0ef41Sopenharmony_ci ['g;x?y#s', bases[0], 'http://a/b/c/g;x?y#s'], 1191cb0ef41Sopenharmony_ci // Changed with RFC 2396bis 1201cb0ef41Sopenharmony_ci // ('', bases[0], CURRENT_DOC_URI], 1211cb0ef41Sopenharmony_ci ['', bases[0], 'http://a/b/c/d;p?q'], 1221cb0ef41Sopenharmony_ci ['.', bases[0], 'http://a/b/c/'], 1231cb0ef41Sopenharmony_ci ['./', bases[0], 'http://a/b/c/'], 1241cb0ef41Sopenharmony_ci ['..', bases[0], 'http://a/b/'], 1251cb0ef41Sopenharmony_ci ['../', bases[0], 'http://a/b/'], 1261cb0ef41Sopenharmony_ci ['../g', bases[0], 'http://a/b/g'], 1271cb0ef41Sopenharmony_ci ['../..', bases[0], 'http://a/'], 1281cb0ef41Sopenharmony_ci ['../../', bases[0], 'http://a/'], 1291cb0ef41Sopenharmony_ci ['../../g', bases[0], 'http://a/g'], 1301cb0ef41Sopenharmony_ci ['../../../g', bases[0], ('http://a/../g', 'http://a/g')], 1311cb0ef41Sopenharmony_ci ['../../../../g', bases[0], ('http://a/../../g', 'http://a/g')], 1321cb0ef41Sopenharmony_ci // Changed with RFC 2396bis 1331cb0ef41Sopenharmony_ci // ('/./g', bases[0], 'http://a/./g'], 1341cb0ef41Sopenharmony_ci ['/./g', bases[0], 'http://a/g'], 1351cb0ef41Sopenharmony_ci // Changed with RFC 2396bis 1361cb0ef41Sopenharmony_ci // ('/../g', bases[0], 'http://a/../g'], 1371cb0ef41Sopenharmony_ci ['/../g', bases[0], 'http://a/g'], 1381cb0ef41Sopenharmony_ci ['g.', bases[0], 'http://a/b/c/g.'], 1391cb0ef41Sopenharmony_ci ['.g', bases[0], 'http://a/b/c/.g'], 1401cb0ef41Sopenharmony_ci ['g..', bases[0], 'http://a/b/c/g..'], 1411cb0ef41Sopenharmony_ci ['..g', bases[0], 'http://a/b/c/..g'], 1421cb0ef41Sopenharmony_ci ['./../g', bases[0], 'http://a/b/g'], 1431cb0ef41Sopenharmony_ci ['./g/.', bases[0], 'http://a/b/c/g/'], 1441cb0ef41Sopenharmony_ci ['g/./h', bases[0], 'http://a/b/c/g/h'], 1451cb0ef41Sopenharmony_ci ['g/../h', bases[0], 'http://a/b/c/h'], 1461cb0ef41Sopenharmony_ci ['g;x=1/./y', bases[0], 'http://a/b/c/g;x=1/y'], 1471cb0ef41Sopenharmony_ci ['g;x=1/../y', bases[0], 'http://a/b/c/y'], 1481cb0ef41Sopenharmony_ci ['g?y/./x', bases[0], 'http://a/b/c/g?y/./x'], 1491cb0ef41Sopenharmony_ci ['g?y/../x', bases[0], 'http://a/b/c/g?y/../x'], 1501cb0ef41Sopenharmony_ci ['g#s/./x', bases[0], 'http://a/b/c/g#s/./x'], 1511cb0ef41Sopenharmony_ci ['g#s/../x', bases[0], 'http://a/b/c/g#s/../x'], 1521cb0ef41Sopenharmony_ci ['http:g', bases[0], ('http:g', 'http://a/b/c/g')], 1531cb0ef41Sopenharmony_ci ['http:', bases[0], ('http:', bases[0])], 1541cb0ef41Sopenharmony_ci // Not sure where this one originated 1551cb0ef41Sopenharmony_ci ['/a/b/c/./../../g', bases[0], 'http://a/a/g'], 1561cb0ef41Sopenharmony_ci 1571cb0ef41Sopenharmony_ci // http://gbiv.com/protocols/uri/test/rel_examples2.html 1581cb0ef41Sopenharmony_ci // slashes in base URI's query args 1591cb0ef41Sopenharmony_ci ['g', bases[1], 'http://a/b/c/g'], 1601cb0ef41Sopenharmony_ci ['./g', bases[1], 'http://a/b/c/g'], 1611cb0ef41Sopenharmony_ci ['g/', bases[1], 'http://a/b/c/g/'], 1621cb0ef41Sopenharmony_ci ['/g', bases[1], 'http://a/g'], 1631cb0ef41Sopenharmony_ci ['//g', bases[1], 'http://g/'], 1641cb0ef41Sopenharmony_ci // Changed in RFC 2396bis 1651cb0ef41Sopenharmony_ci // ('?y', bases[1], 'http://a/b/c/?y'], 1661cb0ef41Sopenharmony_ci ['?y', bases[1], 'http://a/b/c/d;p?y'], 1671cb0ef41Sopenharmony_ci ['g?y', bases[1], 'http://a/b/c/g?y'], 1681cb0ef41Sopenharmony_ci ['g?y/./x', bases[1], 'http://a/b/c/g?y/./x'], 1691cb0ef41Sopenharmony_ci ['g?y/../x', bases[1], 'http://a/b/c/g?y/../x'], 1701cb0ef41Sopenharmony_ci ['g#s', bases[1], 'http://a/b/c/g#s'], 1711cb0ef41Sopenharmony_ci ['g#s/./x', bases[1], 'http://a/b/c/g#s/./x'], 1721cb0ef41Sopenharmony_ci ['g#s/../x', bases[1], 'http://a/b/c/g#s/../x'], 1731cb0ef41Sopenharmony_ci ['./', bases[1], 'http://a/b/c/'], 1741cb0ef41Sopenharmony_ci ['../', bases[1], 'http://a/b/'], 1751cb0ef41Sopenharmony_ci ['../g', bases[1], 'http://a/b/g'], 1761cb0ef41Sopenharmony_ci ['../../', bases[1], 'http://a/'], 1771cb0ef41Sopenharmony_ci ['../../g', bases[1], 'http://a/g'], 1781cb0ef41Sopenharmony_ci 1791cb0ef41Sopenharmony_ci // http://gbiv.com/protocols/uri/test/rel_examples3.html 1801cb0ef41Sopenharmony_ci // slashes in path params 1811cb0ef41Sopenharmony_ci // all of these changed in RFC 2396bis 1821cb0ef41Sopenharmony_ci ['g', bases[2], 'http://a/b/c/d;p=1/g'], 1831cb0ef41Sopenharmony_ci ['./g', bases[2], 'http://a/b/c/d;p=1/g'], 1841cb0ef41Sopenharmony_ci ['g/', bases[2], 'http://a/b/c/d;p=1/g/'], 1851cb0ef41Sopenharmony_ci ['g?y', bases[2], 'http://a/b/c/d;p=1/g?y'], 1861cb0ef41Sopenharmony_ci [';x', bases[2], 'http://a/b/c/d;p=1/;x'], 1871cb0ef41Sopenharmony_ci ['g;x', bases[2], 'http://a/b/c/d;p=1/g;x'], 1881cb0ef41Sopenharmony_ci ['g;x=1/./y', bases[2], 'http://a/b/c/d;p=1/g;x=1/y'], 1891cb0ef41Sopenharmony_ci ['g;x=1/../y', bases[2], 'http://a/b/c/d;p=1/y'], 1901cb0ef41Sopenharmony_ci ['./', bases[2], 'http://a/b/c/d;p=1/'], 1911cb0ef41Sopenharmony_ci ['../', bases[2], 'http://a/b/c/'], 1921cb0ef41Sopenharmony_ci ['../g', bases[2], 'http://a/b/c/g'], 1931cb0ef41Sopenharmony_ci ['../../', bases[2], 'http://a/b/'], 1941cb0ef41Sopenharmony_ci ['../../g', bases[2], 'http://a/b/g'], 1951cb0ef41Sopenharmony_ci 1961cb0ef41Sopenharmony_ci // http://gbiv.com/protocols/uri/test/rel_examples4.html 1971cb0ef41Sopenharmony_ci // double and triple slash, unknown scheme 1981cb0ef41Sopenharmony_ci ['g:h', bases[3], 'g:h'], 1991cb0ef41Sopenharmony_ci ['g', bases[3], 'fred:///s//a/b/g'], 2001cb0ef41Sopenharmony_ci ['./g', bases[3], 'fred:///s//a/b/g'], 2011cb0ef41Sopenharmony_ci ['g/', bases[3], 'fred:///s//a/b/g/'], 2021cb0ef41Sopenharmony_ci ['/g', bases[3], 'fred:///g'], // May change to fred:///s//a/g 2031cb0ef41Sopenharmony_ci ['//g', bases[3], 'fred://g'], // May change to fred:///s//g 2041cb0ef41Sopenharmony_ci ['//g/x', bases[3], 'fred://g/x'], // May change to fred:///s//g/x 2051cb0ef41Sopenharmony_ci ['///g', bases[3], 'fred:///g'], 2061cb0ef41Sopenharmony_ci ['./', bases[3], 'fred:///s//a/b/'], 2071cb0ef41Sopenharmony_ci ['../', bases[3], 'fred:///s//a/'], 2081cb0ef41Sopenharmony_ci ['../g', bases[3], 'fred:///s//a/g'], 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_ci ['../../', bases[3], 'fred:///s//'], 2111cb0ef41Sopenharmony_ci ['../../g', bases[3], 'fred:///s//g'], 2121cb0ef41Sopenharmony_ci ['../../../g', bases[3], 'fred:///s/g'], 2131cb0ef41Sopenharmony_ci // May change to fred:///s//a/../../../g 2141cb0ef41Sopenharmony_ci ['../../../../g', bases[3], 'fred:///g'], 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_ci // http://gbiv.com/protocols/uri/test/rel_examples5.html 2171cb0ef41Sopenharmony_ci // double and triple slash, well-known scheme 2181cb0ef41Sopenharmony_ci ['g:h', bases[4], 'g:h'], 2191cb0ef41Sopenharmony_ci ['g', bases[4], 'http:///s//a/b/g'], 2201cb0ef41Sopenharmony_ci ['./g', bases[4], 'http:///s//a/b/g'], 2211cb0ef41Sopenharmony_ci ['g/', bases[4], 'http:///s//a/b/g/'], 2221cb0ef41Sopenharmony_ci ['/g', bases[4], 'http:///g'], // May change to http:///s//a/g 2231cb0ef41Sopenharmony_ci ['//g', bases[4], 'http://g/'], // May change to http:///s//g 2241cb0ef41Sopenharmony_ci ['//g/x', bases[4], 'http://g/x'], // May change to http:///s//g/x 2251cb0ef41Sopenharmony_ci ['///g', bases[4], 'http:///g'], 2261cb0ef41Sopenharmony_ci ['./', bases[4], 'http:///s//a/b/'], 2271cb0ef41Sopenharmony_ci ['../', bases[4], 'http:///s//a/'], 2281cb0ef41Sopenharmony_ci ['../g', bases[4], 'http:///s//a/g'], 2291cb0ef41Sopenharmony_ci ['../../', bases[4], 'http:///s//'], 2301cb0ef41Sopenharmony_ci ['../../g', bases[4], 'http:///s//g'], 2311cb0ef41Sopenharmony_ci // May change to http:///s//a/../../g 2321cb0ef41Sopenharmony_ci ['../../../g', bases[4], 'http:///s/g'], 2331cb0ef41Sopenharmony_ci // May change to http:///s//a/../../../g 2341cb0ef41Sopenharmony_ci ['../../../../g', bases[4], 'http:///g'], 2351cb0ef41Sopenharmony_ci 2361cb0ef41Sopenharmony_ci // From Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py 2371cb0ef41Sopenharmony_ci ['bar:abc', 'foo:xyz', 'bar:abc'], 2381cb0ef41Sopenharmony_ci ['../abc', 'http://example/x/y/z', 'http://example/x/abc'], 2391cb0ef41Sopenharmony_ci ['http://example/x/abc', 'http://example2/x/y/z', 'http://example/x/abc'], 2401cb0ef41Sopenharmony_ci ['../r', 'http://ex/x/y/z', 'http://ex/x/r'], 2411cb0ef41Sopenharmony_ci ['q/r', 'http://ex/x/y', 'http://ex/x/q/r'], 2421cb0ef41Sopenharmony_ci ['q/r#s', 'http://ex/x/y', 'http://ex/x/q/r#s'], 2431cb0ef41Sopenharmony_ci ['q/r#s/t', 'http://ex/x/y', 'http://ex/x/q/r#s/t'], 2441cb0ef41Sopenharmony_ci ['ftp://ex/x/q/r', 'http://ex/x/y', 'ftp://ex/x/q/r'], 2451cb0ef41Sopenharmony_ci ['', 'http://ex/x/y', 'http://ex/x/y'], 2461cb0ef41Sopenharmony_ci ['', 'http://ex/x/y/', 'http://ex/x/y/'], 2471cb0ef41Sopenharmony_ci ['', 'http://ex/x/y/pdq', 'http://ex/x/y/pdq'], 2481cb0ef41Sopenharmony_ci ['z/', 'http://ex/x/y/', 'http://ex/x/y/z/'], 2491cb0ef41Sopenharmony_ci ['#Animal', 2501cb0ef41Sopenharmony_ci 'file:/swap/test/animal.rdf', 2511cb0ef41Sopenharmony_ci 'file:/swap/test/animal.rdf#Animal'], 2521cb0ef41Sopenharmony_ci ['../abc', 'file:/e/x/y/z', 'file:/e/x/abc'], 2531cb0ef41Sopenharmony_ci ['/example/x/abc', 'file:/example2/x/y/z', 'file:/example/x/abc'], 2541cb0ef41Sopenharmony_ci ['../r', 'file:/ex/x/y/z', 'file:/ex/x/r'], 2551cb0ef41Sopenharmony_ci ['/r', 'file:/ex/x/y/z', 'file:/r'], 2561cb0ef41Sopenharmony_ci ['q/r', 'file:/ex/x/y', 'file:/ex/x/q/r'], 2571cb0ef41Sopenharmony_ci ['q/r#s', 'file:/ex/x/y', 'file:/ex/x/q/r#s'], 2581cb0ef41Sopenharmony_ci ['q/r#', 'file:/ex/x/y', 'file:/ex/x/q/r#'], 2591cb0ef41Sopenharmony_ci ['q/r#s/t', 'file:/ex/x/y', 'file:/ex/x/q/r#s/t'], 2601cb0ef41Sopenharmony_ci ['ftp://ex/x/q/r', 'file:/ex/x/y', 'ftp://ex/x/q/r'], 2611cb0ef41Sopenharmony_ci ['', 'file:/ex/x/y', 'file:/ex/x/y'], 2621cb0ef41Sopenharmony_ci ['', 'file:/ex/x/y/', 'file:/ex/x/y/'], 2631cb0ef41Sopenharmony_ci ['', 'file:/ex/x/y/pdq', 'file:/ex/x/y/pdq'], 2641cb0ef41Sopenharmony_ci ['z/', 'file:/ex/x/y/', 'file:/ex/x/y/z/'], 2651cb0ef41Sopenharmony_ci ['file://meetings.example.com/cal#m1', 2661cb0ef41Sopenharmony_ci 'file:/devel/WWW/2000/10/swap/test/reluri-1.n3', 2671cb0ef41Sopenharmony_ci 'file://meetings.example.com/cal#m1'], 2681cb0ef41Sopenharmony_ci ['file://meetings.example.com/cal#m1', 2691cb0ef41Sopenharmony_ci 'file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3', 2701cb0ef41Sopenharmony_ci 'file://meetings.example.com/cal#m1'], 2711cb0ef41Sopenharmony_ci ['./#blort', 'file:/some/dir/foo', 'file:/some/dir/#blort'], 2721cb0ef41Sopenharmony_ci ['./#', 'file:/some/dir/foo', 'file:/some/dir/#'], 2731cb0ef41Sopenharmony_ci // Ryan Lee 2741cb0ef41Sopenharmony_ci ['./', 'http://example/x/abc.efg', 'http://example/x/'], 2751cb0ef41Sopenharmony_ci 2761cb0ef41Sopenharmony_ci 2771cb0ef41Sopenharmony_ci // Graham Klyne's tests 2781cb0ef41Sopenharmony_ci // http://www.ninebynine.org/Software/HaskellUtils/Network/UriTest.xls 2791cb0ef41Sopenharmony_ci // 01-31 are from Connelly's cases 2801cb0ef41Sopenharmony_ci 2811cb0ef41Sopenharmony_ci // 32-49 2821cb0ef41Sopenharmony_ci ['./q:r', 'http://ex/x/y', 'http://ex/x/q:r'], 2831cb0ef41Sopenharmony_ci ['./p=q:r', 'http://ex/x/y', 'http://ex/x/p=q:r'], 2841cb0ef41Sopenharmony_ci ['?pp/rr', 'http://ex/x/y?pp/qq', 'http://ex/x/y?pp/rr'], 2851cb0ef41Sopenharmony_ci ['y/z', 'http://ex/x/y?pp/qq', 'http://ex/x/y/z'], 2861cb0ef41Sopenharmony_ci ['local/qual@domain.org#frag', 2871cb0ef41Sopenharmony_ci 'mailto:local', 2881cb0ef41Sopenharmony_ci 'mailto:local/qual@domain.org#frag'], 2891cb0ef41Sopenharmony_ci ['more/qual2@domain2.org#frag', 2901cb0ef41Sopenharmony_ci 'mailto:local/qual1@domain1.org', 2911cb0ef41Sopenharmony_ci 'mailto:local/more/qual2@domain2.org#frag'], 2921cb0ef41Sopenharmony_ci ['y?q', 'http://ex/x/y?q', 'http://ex/x/y?q'], 2931cb0ef41Sopenharmony_ci ['/x/y?q', 'http://ex?p', 'http://ex/x/y?q'], 2941cb0ef41Sopenharmony_ci ['c/d', 'foo:a/b', 'foo:a/c/d'], 2951cb0ef41Sopenharmony_ci ['/c/d', 'foo:a/b', 'foo:/c/d'], 2961cb0ef41Sopenharmony_ci ['', 'foo:a/b?c#d', 'foo:a/b?c'], 2971cb0ef41Sopenharmony_ci ['b/c', 'foo:a', 'foo:b/c'], 2981cb0ef41Sopenharmony_ci ['../b/c', 'foo:/a/y/z', 'foo:/a/b/c'], 2991cb0ef41Sopenharmony_ci ['./b/c', 'foo:a', 'foo:b/c'], 3001cb0ef41Sopenharmony_ci ['/./b/c', 'foo:a', 'foo:/b/c'], 3011cb0ef41Sopenharmony_ci ['../../d', 'foo://a//b/c', 'foo://a/d'], 3021cb0ef41Sopenharmony_ci ['.', 'foo:a', 'foo:'], 3031cb0ef41Sopenharmony_ci ['..', 'foo:a', 'foo:'], 3041cb0ef41Sopenharmony_ci 3051cb0ef41Sopenharmony_ci // 50-57[cf. TimBL comments -- 3061cb0ef41Sopenharmony_ci // http://lists.w3.org/Archives/Public/uri/2003Feb/0028.html, 3071cb0ef41Sopenharmony_ci // http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html) 3081cb0ef41Sopenharmony_ci ['abc', 'http://example/x/y%2Fz', 'http://example/x/abc'], 3091cb0ef41Sopenharmony_ci ['../../x%2Fabc', 'http://example/a/x/y/z', 'http://example/a/x%2Fabc'], 3101cb0ef41Sopenharmony_ci ['../x%2Fabc', 'http://example/a/x/y%2Fz', 'http://example/a/x%2Fabc'], 3111cb0ef41Sopenharmony_ci ['abc', 'http://example/x%2Fy/z', 'http://example/x%2Fy/abc'], 3121cb0ef41Sopenharmony_ci ['q%3Ar', 'http://ex/x/y', 'http://ex/x/q%3Ar'], 3131cb0ef41Sopenharmony_ci ['/x%2Fabc', 'http://example/x/y%2Fz', 'http://example/x%2Fabc'], 3141cb0ef41Sopenharmony_ci ['/x%2Fabc', 'http://example/x/y/z', 'http://example/x%2Fabc'], 3151cb0ef41Sopenharmony_ci ['/x%2Fabc', 'http://example/x/y%2Fz', 'http://example/x%2Fabc'], 3161cb0ef41Sopenharmony_ci 3171cb0ef41Sopenharmony_ci // 70-77 3181cb0ef41Sopenharmony_ci ['local2@domain2', 'mailto:local1@domain1?query1', 'mailto:local2@domain2'], 3191cb0ef41Sopenharmony_ci ['local2@domain2?query2', 3201cb0ef41Sopenharmony_ci 'mailto:local1@domain1', 3211cb0ef41Sopenharmony_ci 'mailto:local2@domain2?query2'], 3221cb0ef41Sopenharmony_ci ['local2@domain2?query2', 3231cb0ef41Sopenharmony_ci 'mailto:local1@domain1?query1', 3241cb0ef41Sopenharmony_ci 'mailto:local2@domain2?query2'], 3251cb0ef41Sopenharmony_ci ['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'], 3261cb0ef41Sopenharmony_ci ['local@domain?query2', 'mailto:?query1', 'mailto:local@domain?query2'], 3271cb0ef41Sopenharmony_ci ['?query2', 'mailto:local@domain?query1', 'mailto:local@domain?query2'], 3281cb0ef41Sopenharmony_ci ['http://example/a/b?c/../d', 'foo:bar', 'http://example/a/b?c/../d'], 3291cb0ef41Sopenharmony_ci ['http://example/a/b#c/../d', 'foo:bar', 'http://example/a/b#c/../d'], 3301cb0ef41Sopenharmony_ci 3311cb0ef41Sopenharmony_ci // 82-88 3321cb0ef41Sopenharmony_ci // @isaacs Disagree. Not how browsers do it. 3331cb0ef41Sopenharmony_ci // ['http:this', 'http://example.org/base/uri', 'http:this'], 3341cb0ef41Sopenharmony_ci // @isaacs Added 3351cb0ef41Sopenharmony_ci ['http:this', 'http://example.org/base/uri', 'http://example.org/base/this'], 3361cb0ef41Sopenharmony_ci ['http:this', 'http:base', 'http:this'], 3371cb0ef41Sopenharmony_ci ['.//g', 'f:/a', 'f://g'], 3381cb0ef41Sopenharmony_ci ['b/c//d/e', 'f://example.org/base/a', 'f://example.org/base/b/c//d/e'], 3391cb0ef41Sopenharmony_ci ['m2@example.ord/c2@example.org', 3401cb0ef41Sopenharmony_ci 'mid:m@example.ord/c@example.org', 3411cb0ef41Sopenharmony_ci 'mid:m@example.ord/m2@example.ord/c2@example.org'], 3421cb0ef41Sopenharmony_ci ['mini1.xml', 3431cb0ef41Sopenharmony_ci 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/', 3441cb0ef41Sopenharmony_ci 'file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml'], 3451cb0ef41Sopenharmony_ci ['../b/c', 'foo:a/y/z', 'foo:a/b/c'], 3461cb0ef41Sopenharmony_ci 3471cb0ef41Sopenharmony_ci // changeing auth 3481cb0ef41Sopenharmony_ci ['http://diff:auth@www.example.com', 3491cb0ef41Sopenharmony_ci 'http://asdf:qwer@www.example.com', 3501cb0ef41Sopenharmony_ci 'http://diff:auth@www.example.com/'], 3511cb0ef41Sopenharmony_ci 3521cb0ef41Sopenharmony_ci // changing port 3531cb0ef41Sopenharmony_ci ['https://example.com:81/', 3541cb0ef41Sopenharmony_ci 'https://example.com:82/', 3551cb0ef41Sopenharmony_ci 'https://example.com:81/'], 3561cb0ef41Sopenharmony_ci 3571cb0ef41Sopenharmony_ci // https://github.com/nodejs/node/issues/1435 3581cb0ef41Sopenharmony_ci ['https://another.host.com/', 3591cb0ef41Sopenharmony_ci 'https://user:password@example.org/', 3601cb0ef41Sopenharmony_ci 'https://another.host.com/'], 3611cb0ef41Sopenharmony_ci ['//another.host.com/', 3621cb0ef41Sopenharmony_ci 'https://user:password@example.org/', 3631cb0ef41Sopenharmony_ci 'https://another.host.com/'], 3641cb0ef41Sopenharmony_ci ['http://another.host.com/', 3651cb0ef41Sopenharmony_ci 'https://user:password@example.org/', 3661cb0ef41Sopenharmony_ci 'http://another.host.com/'], 3671cb0ef41Sopenharmony_ci ['mailto:another.host.com', 3681cb0ef41Sopenharmony_ci 'mailto:user@example.org', 3691cb0ef41Sopenharmony_ci 'mailto:another.host.com'], 3701cb0ef41Sopenharmony_ci ['https://example.com/foo', 3711cb0ef41Sopenharmony_ci 'https://user:password@example.com', 3721cb0ef41Sopenharmony_ci 'https://user:password@example.com/foo'], 3731cb0ef41Sopenharmony_ci 3741cb0ef41Sopenharmony_ci // No path at all 3751cb0ef41Sopenharmony_ci ['#hash1', '#hash2', '#hash1'], 3761cb0ef41Sopenharmony_ci]; 3771cb0ef41Sopenharmony_cirelativeTests2.forEach(function(relativeTest) { 3781cb0ef41Sopenharmony_ci const a = url.resolve(relativeTest[1], relativeTest[0]); 3791cb0ef41Sopenharmony_ci const e = url.format(relativeTest[2]); 3801cb0ef41Sopenharmony_ci assert.strictEqual(a, e, 3811cb0ef41Sopenharmony_ci `resolve(${relativeTest[0]}, ${relativeTest[1]})` + 3821cb0ef41Sopenharmony_ci ` == ${e}\n actual=${a}`); 3831cb0ef41Sopenharmony_ci}); 3841cb0ef41Sopenharmony_ci 3851cb0ef41Sopenharmony_ci// If format and parse are inverse operations then 3861cb0ef41Sopenharmony_ci// resolveObject(parse(x), y) == parse(resolve(x, y)) 3871cb0ef41Sopenharmony_ci 3881cb0ef41Sopenharmony_ci// format: [from, path, expected] 3891cb0ef41Sopenharmony_cirelativeTests.forEach(function(relativeTest) { 3901cb0ef41Sopenharmony_ci let actual = url.resolveObject(url.parse(relativeTest[0]), relativeTest[1]); 3911cb0ef41Sopenharmony_ci let expected = url.parse(relativeTest[2]); 3921cb0ef41Sopenharmony_ci 3931cb0ef41Sopenharmony_ci 3941cb0ef41Sopenharmony_ci assert.deepStrictEqual(actual, expected); 3951cb0ef41Sopenharmony_ci 3961cb0ef41Sopenharmony_ci expected = relativeTest[2]; 3971cb0ef41Sopenharmony_ci actual = url.format(actual); 3981cb0ef41Sopenharmony_ci 3991cb0ef41Sopenharmony_ci assert.strictEqual(actual, expected, 4001cb0ef41Sopenharmony_ci `format(${actual}) == ${expected}\n` + 4011cb0ef41Sopenharmony_ci `actual: ${actual}`); 4021cb0ef41Sopenharmony_ci}); 4031cb0ef41Sopenharmony_ci 4041cb0ef41Sopenharmony_ci// format: [to, from, result] 4051cb0ef41Sopenharmony_ci// the test: ['.//g', 'f:/a', 'f://g'] is a fundamental problem 4061cb0ef41Sopenharmony_ci// url.parse('f:/a') does not have a host 4071cb0ef41Sopenharmony_ci// url.resolve('f:/a', './/g') does not have a host because you have moved 4081cb0ef41Sopenharmony_ci// down to the g directory. i.e. f: //g, however when this url is parsed 4091cb0ef41Sopenharmony_ci// f:// will indicate that the host is g which is not the case. 4101cb0ef41Sopenharmony_ci// it is unclear to me how to keep this information from being lost 4111cb0ef41Sopenharmony_ci// it may be that a pathname of ////g should collapse to /g but this seems 4121cb0ef41Sopenharmony_ci// to be a lot of work for an edge case. Right now I remove the test 4131cb0ef41Sopenharmony_ciif (relativeTests2[181][0] === './/g' && 4141cb0ef41Sopenharmony_ci relativeTests2[181][1] === 'f:/a' && 4151cb0ef41Sopenharmony_ci relativeTests2[181][2] === 'f://g') { 4161cb0ef41Sopenharmony_ci relativeTests2.splice(181, 1); 4171cb0ef41Sopenharmony_ci} 4181cb0ef41Sopenharmony_cirelativeTests2.forEach(function(relativeTest) { 4191cb0ef41Sopenharmony_ci let actual = url.resolveObject(url.parse(relativeTest[1]), relativeTest[0]); 4201cb0ef41Sopenharmony_ci let expected = url.parse(relativeTest[2]); 4211cb0ef41Sopenharmony_ci 4221cb0ef41Sopenharmony_ci assert.deepStrictEqual( 4231cb0ef41Sopenharmony_ci actual, 4241cb0ef41Sopenharmony_ci expected, 4251cb0ef41Sopenharmony_ci `expected ${inspect(expected)} but got ${inspect(actual)}` 4261cb0ef41Sopenharmony_ci ); 4271cb0ef41Sopenharmony_ci 4281cb0ef41Sopenharmony_ci expected = url.format(relativeTest[2]); 4291cb0ef41Sopenharmony_ci actual = url.format(actual); 4301cb0ef41Sopenharmony_ci 4311cb0ef41Sopenharmony_ci assert.strictEqual(actual, expected, 4321cb0ef41Sopenharmony_ci `format(${relativeTest[1]}) == ${expected}\n` + 4331cb0ef41Sopenharmony_ci `actual: ${actual}`); 4341cb0ef41Sopenharmony_ci}); 435