We should not expect percent-escaped hostname for invalid URLs
[WebKit-https.git] / LayoutTests / fast / url / script-tests / ipv4.js
1 description("Canonicalization of IPv4 addresses.");
2
3 cases = [ 
4   [".", ""],
5
6   // Regular IP addresses in different bases.
7   ["192.168.0.1", "192.168.0.1"],
8   ["0300.0250.00.01", "192.168.0.1"],
9   ["0xC0.0Xa8.0x0.0x1", "192.168.0.1"],
10
11   // Non-IP addresses due to invalid characters.
12   ["192.168.9.com", ""],
13
14   // Invalid characters for the base should be rejected.
15   ["19a.168.0.1", ""],
16   ["0308.0250.00.01", ""],
17   ["0xCG.0xA8.0x0.0x1", ""],
18
19   // If there are not enough components, the last one should fill them out.
20   ["192", "0.0.0.192"],
21   ["0xC0a80001", "192.168.0.1"],
22   ["030052000001", "192.168.0.1"],
23   ["000030052000001", "192.168.0.1"],
24   ["192.168", "192.0.0.168"],
25   ["192.0x00A80001", "192.168.0.1"],
26   ["0xc0.052000001", "192.168.0.1"],
27   ["192.168.1", "192.168.0.1"],
28
29   // Too many components means not an IP address.
30   ["192.168.0.0.1", ""],
31
32   // We allow a single trailing dot.
33   ["192.168.0.1.", "192.168.0.1"],
34   ["192.168.0.1. hello", ""],
35   ["192.168.0.1..", ""],
36
37   // Two dots in a row means not an IP address.
38   ["192.168..1", ""],
39
40   // Any numerical overflow should be marked as BROKEN.
41   ["0x100.0", ""],
42   ["0x100.0.0", ""],
43   ["0x100.0.0.0", ""],
44   ["0.0x100.0.0", ""],
45   ["0.0.0x100.0", ""],
46   ["0.0.0.0x100", ""],
47   ["0.0.0x10000", ""],
48   ["0.0x1000000", ""],
49   ["0x100000000", ""],
50
51   // Repeat the previous tests, minus 1, to verify boundaries.
52   ["0xFF.0", "255.0.0.0"],
53   ["0xFF.0.0", "255.0.0.0"],
54   ["0xFF.0.0.0", "255.0.0.0"],
55   ["0.0xFF.0.0", "0.255.0.0"],
56   ["0.0.0xFF.0", "0.0.255.0"],
57   ["0.0.0.0xFF", "0.0.0.255"],
58   ["0.0.0xFFFF", "0.0.255.255"],
59   ["0.0xFFFFFF", "0.255.255.255"],
60   ["0xFFFFFFFF", "255.255.255.255"],
61
62   // Old trunctations tests.  They're all "BROKEN" now.
63   ["276.256.0xf1a2.077777", ""],
64   ["192.168.0.257", ""],
65   ["192.168.0xa20001", ""],
66   ["192.015052000001", ""],
67   ["0X12C0a80001", ""],
68   ["276.1.2", ""],
69
70   // Spaces should be rejected.
71   ["192.168.0.1 hello", ""],
72
73   // Very large numbers.
74   ["0000000000000300.0x00000000000000fF.00000000000000001", "192.255.0.1"],
75   ["0000000000000300.0xffffffffFFFFFFFF.3022415481470977", ""],
76
77   // A number has no length limit, but long numbers can still overflow.
78   ["00000000000000000001", "0.0.0.1"],
79   ["0000000000000000100000000000000001", ""],
80
81   // If a long component is non-numeric, it's a hostname, *not* a broken IP.
82   ["0.0.0.000000000000000000z", ""],
83   ["0.0.0.100000000000000000z", ""],
84
85   // Truncation of all zeros should still result in 0.
86   ["0.00.0x.0x0", "0.0.0.0"]
87 ];
88
89 for (var i = 0; i < cases.length; ++i) {
90   test_vector = cases[i][0];
91   expected_result = cases[i][1];
92   if (expected_result === "")
93     expected_result = test_vector.toLowerCase();
94   shouldBe("canonicalize('http://" + test_vector + "/')",
95            "'http://" + expected_result + "/'");
96 }