Merge branch 'jc/checkout-local-track-report'
[git/mingw/j6t.git] / t / t0110-urlmatch-normalization.sh
blob410d5768ca11b1d7e322c135cf18f60f41685b68
1 #!/bin/sh
3 test_description='urlmatch URL normalization'
4 . ./test-lib.sh
6 # The base name of the test url files
7 tu="$TEST_DIRECTORY/t0110/url"
9 # Note that only file: URLs should be allowed without a host
11 test_expect_success 'url scheme' '
12 ! test-urlmatch-normalization "" &&
13 ! test-urlmatch-normalization "_" &&
14 ! test-urlmatch-normalization "scheme" &&
15 ! test-urlmatch-normalization "scheme:" &&
16 ! test-urlmatch-normalization "scheme:/" &&
17 ! test-urlmatch-normalization "scheme://" &&
18 ! test-urlmatch-normalization "file" &&
19 ! test-urlmatch-normalization "file:" &&
20 ! test-urlmatch-normalization "file:/" &&
21 test-urlmatch-normalization "file://" &&
22 ! test-urlmatch-normalization "://acme.co" &&
23 ! test-urlmatch-normalization "x_test://acme.co" &&
24 ! test-urlmatch-normalization "-test://acme.co" &&
25 ! test-urlmatch-normalization "0test://acme.co" &&
26 ! test-urlmatch-normalization "+test://acme.co" &&
27 ! test-urlmatch-normalization ".test://acme.co" &&
28 ! test-urlmatch-normalization "schem%6e://" &&
29 test-urlmatch-normalization "x-Test+v1.0://acme.co" &&
30 test "$(test-urlmatch-normalization -p "AbCdeF://x.Y")" = "abcdef://x.y/"
33 test_expect_success 'url authority' '
34 ! test-urlmatch-normalization "scheme://user:pass@" &&
35 ! test-urlmatch-normalization "scheme://?" &&
36 ! test-urlmatch-normalization "scheme://#" &&
37 ! test-urlmatch-normalization "scheme:///" &&
38 ! test-urlmatch-normalization "scheme://:" &&
39 ! test-urlmatch-normalization "scheme://:555" &&
40 test-urlmatch-normalization "file://user:pass@" &&
41 test-urlmatch-normalization "file://?" &&
42 test-urlmatch-normalization "file://#" &&
43 test-urlmatch-normalization "file:///" &&
44 test-urlmatch-normalization "file://:" &&
45 ! test-urlmatch-normalization "file://:555" &&
46 test-urlmatch-normalization "scheme://user:pass@host" &&
47 test-urlmatch-normalization "scheme://@host" &&
48 test-urlmatch-normalization "scheme://%00@host" &&
49 ! test-urlmatch-normalization "scheme://%%@host" &&
50 ! test-urlmatch-normalization "scheme://host_" &&
51 test-urlmatch-normalization "scheme://user:pass@host/" &&
52 test-urlmatch-normalization "scheme://@host/" &&
53 test-urlmatch-normalization "scheme://host/" &&
54 test-urlmatch-normalization "scheme://host?x" &&
55 test-urlmatch-normalization "scheme://host#x" &&
56 test-urlmatch-normalization "scheme://host/@" &&
57 test-urlmatch-normalization "scheme://host?@x" &&
58 test-urlmatch-normalization "scheme://host#@x" &&
59 test-urlmatch-normalization "scheme://[::1]" &&
60 test-urlmatch-normalization "scheme://[::1]/" &&
61 ! test-urlmatch-normalization "scheme://hos%41/" &&
62 test-urlmatch-normalization "scheme://[invalid....:/" &&
63 test-urlmatch-normalization "scheme://invalid....:]/" &&
64 ! test-urlmatch-normalization "scheme://invalid....:[/" &&
65 ! test-urlmatch-normalization "scheme://invalid....:["
68 test_expect_success 'url port checks' '
69 test-urlmatch-normalization "xyz://q@some.host:" &&
70 test-urlmatch-normalization "xyz://q@some.host:456/" &&
71 ! test-urlmatch-normalization "xyz://q@some.host:0" &&
72 ! test-urlmatch-normalization "xyz://q@some.host:0000000" &&
73 test-urlmatch-normalization "xyz://q@some.host:0000001?" &&
74 test-urlmatch-normalization "xyz://q@some.host:065535#" &&
75 test-urlmatch-normalization "xyz://q@some.host:65535" &&
76 ! test-urlmatch-normalization "xyz://q@some.host:65536" &&
77 ! test-urlmatch-normalization "xyz://q@some.host:99999" &&
78 ! test-urlmatch-normalization "xyz://q@some.host:100000" &&
79 ! test-urlmatch-normalization "xyz://q@some.host:100001" &&
80 test-urlmatch-normalization "http://q@some.host:80" &&
81 test-urlmatch-normalization "https://q@some.host:443" &&
82 test-urlmatch-normalization "http://q@some.host:80/" &&
83 test-urlmatch-normalization "https://q@some.host:443?" &&
84 ! test-urlmatch-normalization "http://q@:8008" &&
85 ! test-urlmatch-normalization "http://:8080" &&
86 ! test-urlmatch-normalization "http://:" &&
87 test-urlmatch-normalization "xyz://q@some.host:456/" &&
88 test-urlmatch-normalization "xyz://[::1]:456/" &&
89 test-urlmatch-normalization "xyz://[::1]:/" &&
90 ! test-urlmatch-normalization "xyz://[::1]:000/" &&
91 ! test-urlmatch-normalization "xyz://[::1]:0%300/" &&
92 ! test-urlmatch-normalization "xyz://[::1]:0x80/" &&
93 ! test-urlmatch-normalization "xyz://[::1]:4294967297/" &&
94 ! test-urlmatch-normalization "xyz://[::1]:030f/"
97 test_expect_success 'url port normalization' '
98 test "$(test-urlmatch-normalization -p "http://x:800")" = "http://x:800/" &&
99 test "$(test-urlmatch-normalization -p "http://x:0800")" = "http://x:800/" &&
100 test "$(test-urlmatch-normalization -p "http://x:00000800")" = "http://x:800/" &&
101 test "$(test-urlmatch-normalization -p "http://x:065535")" = "http://x:65535/" &&
102 test "$(test-urlmatch-normalization -p "http://x:1")" = "http://x:1/" &&
103 test "$(test-urlmatch-normalization -p "http://x:80")" = "http://x/" &&
104 test "$(test-urlmatch-normalization -p "http://x:080")" = "http://x/" &&
105 test "$(test-urlmatch-normalization -p "http://x:000000080")" = "http://x/" &&
106 test "$(test-urlmatch-normalization -p "https://x:443")" = "https://x/" &&
107 test "$(test-urlmatch-normalization -p "https://x:0443")" = "https://x/" &&
108 test "$(test-urlmatch-normalization -p "https://x:000000443")" = "https://x/"
111 test_expect_success 'url general escapes' '
112 ! test-urlmatch-normalization "http://x.y?%fg" &&
113 test "$(test-urlmatch-normalization -p "X://W/%7e%41^%3a")" = "x://w/~A%5E%3A" &&
114 test "$(test-urlmatch-normalization -p "X://W/:/?#[]@")" = "x://w/:/?#[]@" &&
115 test "$(test-urlmatch-normalization -p "X://W/$&()*+,;=")" = "x://w/$&()*+,;=" &&
116 test "$(test-urlmatch-normalization -p "X://W/'\''")" = "x://w/'\''" &&
117 test "$(test-urlmatch-normalization -p "X://W?'\!'")" = "x://w/?'\!'"
120 test_expect_success !MINGW 'url high-bit escapes' '
121 test "$(test-urlmatch-normalization -p "$(cat "$tu-1")")" = "x://q/%01%02%03%04%05%06%07%08%0E%0F%10%11%12" &&
122 test "$(test-urlmatch-normalization -p "$(cat "$tu-2")")" = "x://q/%13%14%15%16%17%18%19%1B%1C%1D%1E%1F%7F" &&
123 test "$(test-urlmatch-normalization -p "$(cat "$tu-3")")" = "x://q/%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F" &&
124 test "$(test-urlmatch-normalization -p "$(cat "$tu-4")")" = "x://q/%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F" &&
125 test "$(test-urlmatch-normalization -p "$(cat "$tu-5")")" = "x://q/%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF" &&
126 test "$(test-urlmatch-normalization -p "$(cat "$tu-6")")" = "x://q/%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF" &&
127 test "$(test-urlmatch-normalization -p "$(cat "$tu-7")")" = "x://q/%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF" &&
128 test "$(test-urlmatch-normalization -p "$(cat "$tu-8")")" = "x://q/%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF" &&
129 test "$(test-urlmatch-normalization -p "$(cat "$tu-9")")" = "x://q/%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF" &&
130 test "$(test-urlmatch-normalization -p "$(cat "$tu-10")")" = "x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF"
133 test_expect_success 'url utf-8 escapes' '
134 test "$(test-urlmatch-normalization -p "$(cat "$tu-11")")" = "x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD"
137 test_expect_success 'url username/password escapes' '
138 test "$(test-urlmatch-normalization -p "x://%41%62(^):%70+d@foo")" = "x://Ab(%5E):p+d@foo/"
141 test_expect_success 'url normalized lengths' '
142 test "$(test-urlmatch-normalization -l "Http://%4d%65:%4d^%70@The.Host")" = 25 &&
143 test "$(test-urlmatch-normalization -l "http://%41:%42@x.y/%61/")" = 17 &&
144 test "$(test-urlmatch-normalization -l "http://@x.y/^")" = 15
147 test_expect_success 'url . and .. segments' '
148 test "$(test-urlmatch-normalization -p "x://y/.")" = "x://y/" &&
149 test "$(test-urlmatch-normalization -p "x://y/./")" = "x://y/" &&
150 test "$(test-urlmatch-normalization -p "x://y/a/.")" = "x://y/a" &&
151 test "$(test-urlmatch-normalization -p "x://y/a/./")" = "x://y/a/" &&
152 test "$(test-urlmatch-normalization -p "x://y/.?")" = "x://y/?" &&
153 test "$(test-urlmatch-normalization -p "x://y/./?")" = "x://y/?" &&
154 test "$(test-urlmatch-normalization -p "x://y/a/.?")" = "x://y/a?" &&
155 test "$(test-urlmatch-normalization -p "x://y/a/./?")" = "x://y/a/?" &&
156 test "$(test-urlmatch-normalization -p "x://y/a/./b/.././../c")" = "x://y/c" &&
157 test "$(test-urlmatch-normalization -p "x://y/a/./b/../.././c/")" = "x://y/c/" &&
158 test "$(test-urlmatch-normalization -p "x://y/a/./b/.././../c/././.././.")" = "x://y/" &&
159 ! test-urlmatch-normalization "x://y/a/./b/.././../c/././.././.." &&
160 test "$(test-urlmatch-normalization -p "x://y/a/./?/././..")" = "x://y/a/?/././.." &&
161 test "$(test-urlmatch-normalization -p "x://y/%2e/")" = "x://y/" &&
162 test "$(test-urlmatch-normalization -p "x://y/%2E/")" = "x://y/" &&
163 test "$(test-urlmatch-normalization -p "x://y/a/%2e./")" = "x://y/" &&
164 test "$(test-urlmatch-normalization -p "x://y/b/.%2E/")" = "x://y/" &&
165 test "$(test-urlmatch-normalization -p "x://y/c/%2e%2E/")" = "x://y/"
168 # http://@foo specifies an empty user name but does not specify a password
169 # http://foo specifies neither a user name nor a password
170 # So they should not be equivalent
171 test_expect_success 'url equivalents' '
172 test-urlmatch-normalization "httP://x" "Http://X/" &&
173 test-urlmatch-normalization "Http://%4d%65:%4d^%70@The.Host" "hTTP://Me:%4D^p@the.HOST:80/" &&
174 ! test-urlmatch-normalization "https://@x.y/^" "httpS://x.y:443/^" &&
175 test-urlmatch-normalization "https://@x.y/^" "httpS://@x.y:0443/^" &&
176 test-urlmatch-normalization "https://@x.y/^/../abc" "httpS://@x.y:0443/abc" &&
177 test-urlmatch-normalization "https://@x.y/^/.." "httpS://@x.y:0443/"
180 test_done