standard-url.js revision db951b2c4c8fce1304a13d97dec4ae14be629380
1description("Canonicalization of standard URLs");
2
3cases = [
4  ["http://www.google.com/foo?bar=baz#", "http://www.google.com/foo?bar=baz#"],
5  ["http://[www.google.com]/", "http://[www.google.com]/"],
6  // Disabled because whitespace gets treated different in this API.
7  // ["ht\ttp:@www.google.com:80/;p?#", "ht%09tp://www.google.com:80/;p?#"],
8  ["http:////////user:@google.com:99?foo", "http://user@google.com:99/?foo"],
9  // Disabled because this gets treated as a relative URL.
10  // ["www.google.com", ":www.google.com/"],
11  ["http://192.0x00A80001", "http://192.168.0.1/"],
12  ["http://www/foo%2Ehtml", "http://www/foo.html"],
13  ["http://user:pass@/", "http://user:pass@/"],
14  ["http://%25DOMAIN:foobar@foodomain.com/", "http://%25DOMAIN:foobar@foodomain.com/"],
15  // Backslashes should get converted to forward slashes.
16  ["http:\\\\\\\\www.google.com\\\\foo", "http://www.google.com/foo"],
17  // Busted refs shouldn't make the whole thing fail.
18  ["http://www.google.com/asdf#\\ud800", "http://www.google.com/asdf#\\uFFFD"],
19  // Basic port tests.
20  ["http://foo:80/", "http://foo/"],
21  ["http://foo:81/", "http://foo:81/"],
22  ["httpa://foo:80/", "httpa://foo:80/"],
23  ["http://foo:-80/", "http://foo:-80/"],
24  ["https://foo:443/", "https://foo/"],
25  ["https://foo:80/", "https://foo:80/"],
26  ["ftp://foo:21/", "ftp://foo/"],
27  ["ftp://foo:80/", "ftp://foo:80/"],
28  ["gopher://foo:70/", "gopher://foo/"],
29  ["gopher://foo:443/", "gopher://foo:443/"],
30  ["ws://foo:80/", "ws://foo/"],
31  ["ws://foo:81/", "ws://foo:81/"],
32  ["ws://foo:443/", "ws://foo:443/"],
33  ["ws://foo:815/", "ws://foo:815/"],
34  ["wss://foo:80/", "wss://foo:80/"],
35  ["wss://foo:81/", "wss://foo:81/"],
36  ["wss://foo:443/", "wss://foo/"],
37  ["wss://foo:815/", "wss://foo:815/"],
38  ["http:/example.com/", "http://example.com/"],
39  ["ftp:/example.com/", "ftp://example.com/"],
40  ["https:/example.com/", "https://example.com/"],
41  ["madeupscheme:/example.com/", "madeupscheme:/example.com/"],
42  ["file:/example.com/", "file://localhost/example.com/"],
43  ["ftps:/example.com/", "ftps:/example.com/"],
44  ["gopher:/example.com/", "gopher://example.com/"],
45  ["ws:/example.com/", "ws://example.com/"],
46  ["wss:/example.com/", "wss://example.com/"],
47  ["data:/example.com/", "data:/example.com/"],
48  ["javascript:/example.com/", "javascript:/example.com/"],
49  ["mailto:/example.com/", "mailto:/example.com/"],
50  ["http:example.com/", "http://example.com/"],
51  ["ftp:example.com/", "ftp://example.com/"],
52  ["https:example.com/", "https://example.com/"],
53  ["madeupscheme:example.com/", "madeupscheme:example.com/"],
54  ["ftps:example.com/", "ftps:example.com/"],
55  ["gopher:example.com/", "gopher://example.com/"],
56  ["ws:example.com/", "ws://example.com/"],
57  ["wss:example.com/", "wss://example.com/"],
58  ["data:example.com/", "data:example.com/"],
59  ["javascript:example.com/", "javascript:example.com/"],
60  ["mailto:example.com/", "mailto:example.com/"],
61];
62
63for (var i = 0; i < cases.length; ++i) {
64  test_vector = cases[i][0];
65  expected_result = cases[i][1];
66  shouldBe("canonicalize('" + test_vector + "')",
67           "'" + expected_result + "'");
68}
69
70var successfullyParsed = true;
71