OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library uriTest; | 5 library uriTest; |
6 | 6 |
7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 testUri(String uriText, bool isAbsolute) { | 10 testUri(String uriText, bool isAbsolute) { |
11 var uri = Uri.parse(uriText); | 11 var uri = Uri.parse(uriText); |
12 | 12 |
13 // Test that parsing a substring works the same as parsing the string. | |
14 String wrapper = "://@[]:/%?#"; | |
15 var embeddedUri = Uri.parse( | |
16 "$wrapper$uri$wrapper", wrapper.length, uriText.length + wrapper.length); | |
17 | |
18 Expect.equals(uri, embeddedUri); | |
19 Expect.equals(isAbsolute, uri.isAbsolute); | 13 Expect.equals(isAbsolute, uri.isAbsolute); |
20 Expect.stringEquals(uriText, uri.toString()); | 14 Expect.stringEquals(uriText, uri.toString()); |
21 | 15 |
22 // Test equals and hashCode members. | 16 // Test equals and hashCode members. |
23 var uri2 = Uri.parse(uriText); | 17 var uri2 = Uri.parse(uriText); |
24 Expect.equals(uri, uri2); | 18 Expect.equals(uri, uri2); |
25 Expect.equals(uri.hashCode, uri2.hashCode); | 19 Expect.equals(uri.hashCode, uri2.hashCode); |
26 | 20 |
27 // Test that removeFragment doesn't change anything else. | 21 // Test that removeFragment doesn't change anything else. |
28 if (uri.hasFragment) { | 22 if (uri.hasFragment) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } else { | 75 } else { |
82 Expect.throws(() => Uri.encodeQueryComponent(orig, encoding: ASCII), | 76 Expect.throws(() => Uri.encodeQueryComponent(orig, encoding: ASCII), |
83 (e) => e is ArgumentError); | 77 (e) => e is ArgumentError); |
84 } | 78 } |
85 } | 79 } |
86 | 80 |
87 testUriPerRFCs() { | 81 testUriPerRFCs() { |
88 final urisSample = "http://a/b/c/d;p?q"; | 82 final urisSample = "http://a/b/c/d;p?q"; |
89 Uri base = Uri.parse(urisSample); | 83 Uri base = Uri.parse(urisSample); |
90 testResolve(expect, relative) { | 84 testResolve(expect, relative) { |
91 String name = "$base << $relative"; | 85 Expect.stringEquals(expect, base.resolve(relative).toString()); |
92 Expect.stringEquals(expect, base.resolve(relative).toString(), name); | |
93 } | 86 } |
94 | 87 |
95 // From RFC 3986. | 88 // From RFC 3986. |
96 testResolve("g:h", "g:h"); | 89 testResolve("g:h", "g:h"); |
97 testResolve("http://a/b/c/g", "g"); | 90 testResolve("http://a/b/c/g", "g"); |
98 testResolve("http://a/b/c/g", "./g"); | 91 testResolve("http://a/b/c/g", "./g"); |
99 testResolve("http://a/b/c/g/", "g/"); | 92 testResolve("http://a/b/c/g/", "g/"); |
100 testResolve("http://a/g", "/g"); | 93 testResolve("http://a/g", "/g"); |
101 testResolve("http://g", "//g"); | 94 testResolve("http://g", "//g"); |
102 testResolve("http://a/b/c/d;p?y", "?y"); | 95 testResolve("http://a/b/c/d;p?y", "?y"); |
(...skipping 29 matching lines...) Expand all Loading... |
132 testResolve("http://a/b/c/y", "g;x=1/../y"); | 125 testResolve("http://a/b/c/y", "g;x=1/../y"); |
133 testResolve("http://a/b/c/g?y/./x", "g?y/./x"); | 126 testResolve("http://a/b/c/g?y/./x", "g?y/./x"); |
134 testResolve("http://a/b/c/g?y/../x", "g?y/../x"); | 127 testResolve("http://a/b/c/g?y/../x", "g?y/../x"); |
135 testResolve("http://a/b/c/g#s/./x", "g#s/./x"); | 128 testResolve("http://a/b/c/g#s/./x", "g#s/./x"); |
136 testResolve("http://a/b/c/g#s/../x", "g#s/../x"); | 129 testResolve("http://a/b/c/g#s/../x", "g#s/../x"); |
137 testResolve("http:g", "http:g"); | 130 testResolve("http:g", "http:g"); |
138 | 131 |
139 // Additional tests (not from RFC 3986). | 132 // Additional tests (not from RFC 3986). |
140 testResolve("http://a/b/g;p/h;s", "../g;p/h;s"); | 133 testResolve("http://a/b/g;p/h;s", "../g;p/h;s"); |
141 | 134 |
142 base = Uri.parse("s:a/b"); | |
143 testResolve("s:a/c", "c"); | |
144 testResolve("s:/c", "../c"); | |
145 | |
146 base = Uri.parse("S:a/b"); | |
147 testResolve("s:a/c", "c"); | |
148 testResolve("s:/c", "../c"); | |
149 | |
150 base = Uri.parse("s:foo"); | |
151 testResolve("s:bar", "bar"); | |
152 testResolve("s:bar", "../bar"); | |
153 | |
154 base = Uri.parse("S:foo"); | |
155 testResolve("s:bar", "bar"); | |
156 testResolve("s:bar", "../bar"); | |
157 | |
158 // Special-case (deliberate non-RFC behavior). | |
159 base = Uri.parse("foo/bar"); | |
160 testResolve("foo/baz", "baz"); | |
161 testResolve("baz", "../baz"); | |
162 | |
163 base = Uri.parse("s:/foo"); | |
164 testResolve("s:/bar", "bar"); | |
165 testResolve("s:/bar", "../bar"); | |
166 | |
167 base = Uri.parse("S:/foo"); | |
168 testResolve("s:/bar", "bar"); | |
169 testResolve("s:/bar", "../bar"); | |
170 | |
171 // Test non-URI base (no scheme, no authority, relative path). | 135 // Test non-URI base (no scheme, no authority, relative path). |
172 base = Uri.parse("a/b/c?_#_"); | 136 base = Uri.parse("a/b/c?_#_"); |
173 testResolve("a/b/g?q#f", "g?q#f"); | 137 testResolve("a/b/g?q#f", "g?q#f"); |
174 testResolve("./", "../.."); | 138 testResolve("./", "../.."); |
175 testResolve("../", "../../.."); | 139 testResolve("../", "../../.."); |
176 testResolve("a/b/", "."); | 140 testResolve("a/b/", "."); |
177 testResolve("c", "../../c"); // Deliberate non-RFC behavior. | 141 testResolve("c", "../../c"); |
178 base = Uri.parse("../../a/b/c?_#_"); // Initial ".." in base url. | 142 base = Uri.parse("../../a/b/c?_#_"); // Initial ".." in base url. |
179 testResolve("../../a/d", "../d"); | 143 testResolve("../../a/d", "../d"); |
180 testResolve("../../../d", "../../../d"); | 144 testResolve("../../../d", "../../../d"); |
181 | 145 |
182 base = Uri.parse("s://h/p?q#f"); // A simple base. | 146 base = Uri.parse("s:a/b"); |
183 // Simple references: | 147 testResolve("s:/c", "../c"); |
184 testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F"); | |
185 testResolve("s://h2/P?Q#F", "//h2/P?Q#F"); | |
186 testResolve("s://h/P?Q#F", "/P?Q#F"); | |
187 testResolve("s://h/p?Q#F", "?Q#F"); | |
188 testResolve("s://h/p?q#F", "#F"); | |
189 testResolve("s://h/p?q", ""); | |
190 // Non-simple references: | |
191 testResolve("s2://I@h2/P?Q#F%20", "s2://I@h2/P?Q#F%20"); | |
192 testResolve("s://I@h2/P?Q#F%20", "//I@h2/P?Q#F%20"); | |
193 testResolve("s://h2/P?Q#F%20", "//h2/P?Q#F%20"); | |
194 testResolve("s://h/P?Q#F%20", "/P?Q#F%20"); | |
195 testResolve("s://h/p?Q#F%20", "?Q#F%20"); | |
196 testResolve("s://h/p?q#F%20", "#F%20"); | |
197 | |
198 base = Uri.parse("s://h/p1/p2/p3"); // A simple base with a path. | |
199 testResolve("s://h/p1/p2/", "."); | |
200 testResolve("s://h/p1/p2/", "./"); | |
201 testResolve("s://h/p1/", ".."); | |
202 testResolve("s://h/p1/", "../"); | |
203 testResolve("s://h/", "../.."); | |
204 testResolve("s://h/", "../../"); | |
205 testResolve("s://h/p1/%20", "../%20"); | |
206 testResolve("s://h/", "../../../.."); | |
207 testResolve("s://h/", "../../../../"); | |
208 | |
209 base = Uri.parse("s://h/p?q#f%20"); // A non-simpe base. | |
210 // Simple references: | |
211 testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F"); | |
212 testResolve("s://h2/P?Q#F", "//h2/P?Q#F"); | |
213 testResolve("s://h/P?Q#F", "/P?Q#F"); | |
214 testResolve("s://h/p?Q#F", "?Q#F"); | |
215 testResolve("s://h/p?q#F", "#F"); | |
216 testResolve("s://h/p?q", ""); | |
217 // Non-simple references: | |
218 testResolve("s2://I@h2/P?Q#F%20", "s2://I@h2/P?Q#F%20"); | |
219 testResolve("s://I@h2/P?Q#F%20", "//I@h2/P?Q#F%20"); | |
220 testResolve("s://h2/P?Q#F%20", "//h2/P?Q#F%20"); | |
221 testResolve("s://h/P?Q#F%20", "/P?Q#F%20"); | |
222 testResolve("s://h/p?Q#F%20", "?Q#F%20"); | |
223 testResolve("s://h/p?q#F%20", "#F%20"); | |
224 | |
225 base = Uri.parse("S://h/p1/p2/p3"); // A non-simple base with a path. | |
226 testResolve("s://h/p1/p2/", "."); | |
227 testResolve("s://h/p1/p2/", "./"); | |
228 testResolve("s://h/p1/", ".."); | |
229 testResolve("s://h/p1/", "../"); | |
230 testResolve("s://h/", "../.."); | |
231 testResolve("s://h/", "../../"); | |
232 testResolve("s://h/p1/%20", "../%20"); | |
233 testResolve("s://h/", "../../../.."); | |
234 testResolve("s://h/", "../../../../"); | |
235 | |
236 base = Uri.parse("../../../"); // A simple relative path. | |
237 testResolve("../../../a", "a"); | |
238 testResolve("../../../../a", "../a"); | |
239 testResolve("../../../a%20", "a%20"); | |
240 testResolve("../../../../a%20", "../a%20"); | |
241 | |
242 // Tests covering the branches of the merge algorithm in RFC 3986 | |
243 // with both simple and complex base URIs. | |
244 for (var b in ["s://a/pa/pb?q#f", "s://a/pa/pb?q#f%20"]) { | |
245 var origBase = Uri.parse(b); | |
246 base = origBase; | |
247 | |
248 // if defined(R.scheme) then ... | |
249 testResolve("s2://a2/p2?q2#f2", "s2://a2/p2?q2#f2"); | |
250 // else, if defined(R.authority) then ... | |
251 testResolve("s://a2/p2?q2#f2", "//a2/p2?q2#f2"); | |
252 testResolve("s://a2/?q2#f2", "//a2/../?q2#f2"); | |
253 testResolve("s://a2?q2#f2", "//a2?q2#f2"); | |
254 testResolve("s://a2#f2", "//a2#f2"); | |
255 testResolve("s://a2", "//a2"); | |
256 // else, if (R.path == "") then ... | |
257 // if defined(R.query) then | |
258 testResolve("s://a/pa/pb?q2#f2", "?q2#f2"); | |
259 testResolve("s://a/pa/pb?q2", "?q2"); | |
260 // else | |
261 testResolve("s://a/pa/pb?q#f2", "#f2"); | |
262 testResolve("s://a/pa/pb?q", ""); | |
263 // else, if (R.path starts-with "/") then ... | |
264 testResolve("s://a/p2?q2#f2", "/p2?q2#f2"); | |
265 testResolve("s://a/?q2#f2", "/?q2#f2"); | |
266 testResolve("s://a/#f2", "/#f2"); | |
267 testResolve("s://a/", "/"); | |
268 testResolve("s://a/", "/../"); | |
269 // else ... T.path = merge(Base.path, R.path) | |
270 // ... remove-dot-fragments(T.path) ... | |
271 // (Cover the merge function and the remove-dot-fragments functions too). | |
272 | |
273 // If base has authority and empty path ... | |
274 var emptyPathBase = Uri.parse(b.replaceFirst("/pa/pb", "")); | |
275 base = emptyPathBase; | |
276 testResolve("s://a/p2?q2#f2", "p2?q2#f2"); | |
277 testResolve("s://a/p2#f2", "p2#f2"); | |
278 testResolve("s://a/p2", "p2"); | |
279 | |
280 base = origBase; | |
281 // otherwise | |
282 // (Cover both no authority and non-empty path and both). | |
283 var noAuthEmptyPathBase = Uri.parse(b.replaceFirst("//a/pa/pb", "")); | |
284 var noAuthAbsPathBase = Uri.parse(b.replaceFirst("//a", "")); | |
285 var noAuthRelPathBase = Uri.parse(b.replaceFirst("//a/", "")); | |
286 var noAuthRelSinglePathBase = Uri.parse(b.replaceFirst("//a/pa/", "")); | |
287 | |
288 testResolve("s://a/pa/p2?q2#f2", "p2?q2#f2"); | |
289 testResolve("s://a/pa/p2#f2", "p2#f2"); | |
290 testResolve("s://a/pa/p2", "p2"); | |
291 | |
292 base = noAuthEmptyPathBase; | |
293 testResolve("s:p2?q2#f2", "p2?q2#f2"); | |
294 testResolve("s:p2#f2", "p2#f2"); | |
295 testResolve("s:p2", "p2"); | |
296 | |
297 base = noAuthAbsPathBase; | |
298 testResolve("s:/pa/p2?q2#f2", "p2?q2#f2"); | |
299 testResolve("s:/pa/p2#f2", "p2#f2"); | |
300 testResolve("s:/pa/p2", "p2"); | |
301 | |
302 base = noAuthRelPathBase; | |
303 testResolve("s:pa/p2?q2#f2", "p2?q2#f2"); | |
304 testResolve("s:pa/p2#f2", "p2#f2"); | |
305 testResolve("s:pa/p2", "p2"); | |
306 | |
307 base = noAuthRelSinglePathBase; | |
308 testResolve("s:p2?q2#f2", "p2?q2#f2"); | |
309 testResolve("s:p2#f2", "p2#f2"); | |
310 testResolve("s:p2", "p2"); | |
311 | |
312 // Then remove dot segments. | |
313 | |
314 // A. if input buffer starts with "../" or "./". | |
315 // This only happens if base has only a single (may be empty) segment and | |
316 // no slash. | |
317 base = emptyPathBase; | |
318 testResolve("s://a/p2", "../p2"); | |
319 testResolve("s://a/", "../"); | |
320 testResolve("s://a/", ".."); | |
321 testResolve("s://a/p2", "./p2"); | |
322 testResolve("s://a/", "./"); | |
323 testResolve("s://a/", "."); | |
324 testResolve("s://a/p2", "../../p2"); | |
325 testResolve("s://a/p2", "../../././p2"); | |
326 | |
327 base = noAuthRelSinglePathBase; | |
328 testResolve("s:p2", "../p2"); | |
329 testResolve("s:", "../"); | |
330 testResolve("s:", ".."); | |
331 testResolve("s:p2", "./p2"); | |
332 testResolve("s:", "./"); | |
333 testResolve("s:", "."); | |
334 testResolve("s:p2", "../../p2"); | |
335 testResolve("s:p2", "../../././p2"); | |
336 | |
337 // B. if input buffer starts with "/./" or is "/.". replace with "/". | |
338 // (The URI implementation removes the "." path segments when parsing, | |
339 // so this case isn't handled by merge). | |
340 base = origBase; | |
341 testResolve("s://a/pa/p2", "./p2"); | |
342 | |
343 // C. if input buffer starts with "/../" or is "/..", replace with "/" | |
344 // and remove preceeding segment. | |
345 testResolve("s://a/p2", "../p2"); | |
346 var longPathBase = Uri.parse(b.replaceFirst("/pb", "/pb/pc/pd")); | |
347 base = longPathBase; | |
348 testResolve("s://a/pa/pb/p2", "../p2"); | |
349 testResolve("s://a/pa/p2", "../../p2"); | |
350 testResolve("s://a/p2", "../../../p2"); | |
351 testResolve("s://a/p2", "../../../../p2"); | |
352 var noAuthRelLongPathBase = | |
353 Uri.parse(b.replaceFirst("//a/pa/pb", "pa/pb/pc/pd")); | |
354 base = noAuthRelLongPathBase; | |
355 testResolve("s:pa/pb/p2", "../p2"); | |
356 testResolve("s:pa/p2", "../../p2"); | |
357 testResolve("s:/p2", "../../../p2"); | |
358 testResolve("s:/p2", "../../../../p2"); | |
359 | |
360 // D. if the input buffer contains only ".." or ".", remove it. | |
361 base = noAuthEmptyPathBase; | |
362 testResolve("s:", ".."); | |
363 testResolve("s:", "."); | |
364 base = noAuthRelSinglePathBase; | |
365 testResolve("s:", ".."); | |
366 testResolve("s:", "."); | |
367 } | |
368 } | 148 } |
369 | 149 |
370 void testResolvePath(String expected, String path) { | 150 void testResolvePath(String expected, String path) { |
371 Expect.equals(expected, | 151 Expect.equals(expected, |
372 new Uri(path: '/').resolveUri(new Uri(path: path)).path); | 152 new Uri(path: '/').resolveUri(new Uri(path: path)).path); |
373 Expect.equals( | 153 Expect.equals( |
374 "http://localhost$expected", | 154 "http://localhost$expected", |
375 Uri.parse("http://localhost").resolveUri(new Uri(path: path)).toString()); | 155 Uri.parse("http://localhost").resolveUri(new Uri(path: path)).toString()); |
376 } | 156 } |
377 | 157 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 var char = UNRESERVED[i]; | 327 var char = UNRESERVED[i]; |
548 var escape = "%" + char.codeUnitAt(0).toRadixString(16); // all > 0xf. | 328 var escape = "%" + char.codeUnitAt(0).toRadixString(16); // all > 0xf. |
549 | 329 |
550 uri = Uri.parse("s://xX${escape}xX@yY${escape}yY/zZ${escape}zZ" | 330 uri = Uri.parse("s://xX${escape}xX@yY${escape}yY/zZ${escape}zZ" |
551 "?vV${escape}vV#wW${escape}wW"); | 331 "?vV${escape}vV#wW${escape}wW"); |
552 Expect.equals("xX${char}xX", uri.userInfo); | 332 Expect.equals("xX${char}xX", uri.userInfo); |
553 Expect.equals("yY${char}yY".toLowerCase(), uri.host); | 333 Expect.equals("yY${char}yY".toLowerCase(), uri.host); |
554 Expect.equals("/zZ${char}zZ", uri.path); | 334 Expect.equals("/zZ${char}zZ", uri.path); |
555 Expect.equals("vV${char}vV", uri.query); | 335 Expect.equals("vV${char}vV", uri.query); |
556 Expect.equals("wW${char}wW", uri.fragment); | 336 Expect.equals("wW${char}wW", uri.fragment); |
557 | |
558 uri = Uri.parse("s://yY${escape}yY/zZ${escape}zZ" | |
559 "?vV${escape}vV#wW${escape}wW"); | |
560 Expect.equals("yY${char}yY".toLowerCase(), uri.host); | |
561 Expect.equals("/zZ${char}zZ", uri.path); | |
562 Expect.equals("vV${char}vV", uri.query); | |
563 Expect.equals("wW${char}wW", uri.fragment); | |
564 } | 337 } |
565 | 338 |
566 // Escapes of reserved characters are kept, but upper-cased. | 339 // Escapes of reserved characters are kept, but upper-cased. |
567 for (var escape in ["%00", "%1f", "%7F", "%fF"]) { | 340 for (var escape in ["%00", "%1f", "%7F", "%fF"]) { |
568 uri = Uri.parse("s://xX${escape}xX@yY${escape}yY/zZ${escape}zZ" | 341 uri = Uri.parse("s://xX${escape}xX@yY${escape}yY/zZ${escape}zZ" |
569 "?vV${escape}vV#wW${escape}wW"); | 342 "?vV${escape}vV#wW${escape}wW"); |
570 var normalizedEscape = escape.toUpperCase(); | 343 var normalizedEscape = escape.toUpperCase(); |
571 Expect.equals("xX${normalizedEscape}xX", uri.userInfo); | 344 Expect.equals("xX${normalizedEscape}xX", uri.userInfo); |
572 Expect.equals("yy${normalizedEscape}yy", uri.host); | 345 Expect.equals("yy${normalizedEscape}yy", uri.host); |
573 Expect.equals("/zZ${normalizedEscape}zZ", uri.path); | 346 Expect.equals("/zZ${normalizedEscape}zZ", uri.path); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 Expect.equals("scheme:///?#", Uri.parse("scheme:///?#").toString()); | 393 Expect.equals("scheme:///?#", Uri.parse("scheme:///?#").toString()); |
621 Expect.equals("scheme:///#", | 394 Expect.equals("scheme:///#", |
622 new Uri(scheme: "scheme", host: "", path: "/", | 395 new Uri(scheme: "scheme", host: "", path: "/", |
623 query: "", fragment: "").toString()); | 396 query: "", fragment: "").toString()); |
624 } | 397 } |
625 | 398 |
626 void testReplace() { | 399 void testReplace() { |
627 var uris = [ | 400 var uris = [ |
628 Uri.parse(""), | 401 Uri.parse(""), |
629 Uri.parse("a://@:/?#"), | 402 Uri.parse("a://@:/?#"), |
630 Uri.parse("a://:/?#"), // Parsed as simple URI. | |
631 Uri.parse("a://b@c:4/e/f?g#h"), | 403 Uri.parse("a://b@c:4/e/f?g#h"), |
632 Uri.parse("a://c:4/e/f?g#h"), // Parsed as simple URI. | |
633 Uri.parse("$SCHEMECHAR://$REGNAMECHAR:$DIGIT/$PCHAR/$PCHAR" | |
634 "?$QUERYCHAR#$QUERYCHAR"), // Parsed as simple URI. | |
635 Uri.parse("$SCHEMECHAR://$USERINFOCHAR@$REGNAMECHAR:$DIGIT/$PCHAR/$PCHAR" | 404 Uri.parse("$SCHEMECHAR://$USERINFOCHAR@$REGNAMECHAR:$DIGIT/$PCHAR/$PCHAR" |
636 "?$QUERYCHAR#$QUERYCHAR"), | 405 "?$QUERYCHAR#$QUERYCHAR"), |
637 ]; | 406 ]; |
638 for (var uri1 in uris) { | 407 for (var uri1 in uris) { |
639 for (var uri2 in uris) { | 408 for (var uri2 in uris) { |
640 if (identical(uri1, uri2)) continue; | 409 if (identical(uri1, uri2)) continue; |
641 var scheme = uri1.scheme; | 410 var scheme = uri1.scheme; |
642 var userInfo = uri1.hasAuthority ? uri1.userInfo : ""; | 411 var userInfo = uri1.hasAuthority ? uri1.userInfo : ""; |
643 var host = uri1.hasAuthority ? uri1.host : null; | 412 var host = uri1.hasAuthority ? uri1.host : null; |
644 var port = uri1.hasAuthority ? uri1.port : 0; | 413 var port = uri1.hasAuthority ? uri1.port : 0; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 uri = uri.replace(fragment: "fragment"); | 463 uri = uri.replace(fragment: "fragment"); |
695 Expect.isFalse(uri.hasAuthority); | 464 Expect.isFalse(uri.hasAuthority); |
696 | 465 |
697 uri = new Uri(scheme: "foo", path: "bar"); | 466 uri = new Uri(scheme: "foo", path: "bar"); |
698 uri = uri.replace( | 467 uri = uri.replace( |
699 queryParameters: {"x": ["42", "37"], "y": ["43", "38"]}); | 468 queryParameters: {"x": ["42", "37"], "y": ["43", "38"]}); |
700 var params = uri.queryParametersAll; | 469 var params = uri.queryParametersAll; |
701 Expect.equals(2, params.length); | 470 Expect.equals(2, params.length); |
702 Expect.listEquals(["42", "37"], params["x"]); | 471 Expect.listEquals(["42", "37"], params["x"]); |
703 Expect.listEquals(["43", "38"], params["y"]); | 472 Expect.listEquals(["43", "38"], params["y"]); |
704 | |
705 // Test replacing with empty strings. | |
706 uri = Uri.parse("s://a:1/b/c?d#e"); | |
707 Expect.equals("s://a:1/b/c?d#", uri.replace(fragment: "").toString()); | |
708 Expect.equals("s://a:1/b/c?#e", uri.replace(query: "").toString()); | |
709 Expect.equals("s://a:1?d#e", uri.replace(path: "").toString()); | |
710 Expect.equals("s://:1/b/c?d#e", uri.replace(host: "").toString()); | |
711 } | 473 } |
712 | 474 |
713 main() { | 475 main() { |
714 testUri("http:", true); | 476 testUri("http:", true); |
715 testUri("file:///", true); | 477 testUri("file:///", true); |
716 testUri("file", false); | 478 testUri("file", false); |
717 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); | 479 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); |
718 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", | 480 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", |
719 false); | 481 false); |
720 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", | 482 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", |
721 new Uri( | 483 new Uri( |
722 scheme: "http", | 484 scheme: "http", |
723 userInfo: "user", | 485 userInfo: "user", |
724 host: "example.com", | 486 host: "example.com", |
725 port: 80, | 487 port: 80, |
726 path: "/a/b/c", | 488 path: "/a/b/c", |
727 query: "query", | 489 query: "query", |
728 fragment: "fragment").toString()); | 490 fragment: "fragment").toString()); |
729 Expect.stringEquals("/a/b/c/", | 491 Expect.stringEquals("/a/b/c/", |
730 new Uri( | 492 new Uri( |
731 scheme: null, | 493 scheme: null, |
732 userInfo: null, | 494 userInfo: null, |
733 host: null, | 495 host: null, |
734 port: 0, | 496 port: 0, |
735 path: "/a/b/c/", | 497 path: "/a/b/c/", |
736 query: null, | 498 query: null, |
737 fragment: null).toString()); | 499 fragment: null).toString()); |
738 Expect.stringEquals("file:///", Uri.parse("file:").toString()); | 500 Expect.stringEquals("file:///", Uri.parse("file:").toString()); |
739 Expect.stringEquals("file:///", Uri.parse("file:/").toString()); | |
740 Expect.stringEquals("file:///", Uri.parse("file:").toString()); | |
741 Expect.stringEquals("file:///foo", Uri.parse("file:foo").toString()); | |
742 Expect.stringEquals("file:///foo", Uri.parse("file:/foo").toString()); | |
743 Expect.stringEquals("file://foo/", Uri.parse("file://foo").toString()); | |
744 | 501 |
745 testResolvePath("/a/g", "/a/b/c/./../../g"); | 502 testResolvePath("/a/g", "/a/b/c/./../../g"); |
746 testResolvePath("/a/g", "/a/b/c/./../../g"); | 503 testResolvePath("/a/g", "/a/b/c/./../../g"); |
747 testResolvePath("/mid/6", "mid/content=5/../6"); | 504 testResolvePath("/mid/6", "mid/content=5/../6"); |
748 testResolvePath("/a/b/e", "a/b/c/d/../../e"); | 505 testResolvePath("/a/b/e", "a/b/c/d/../../e"); |
749 testResolvePath("/a/b/e", "../a/b/c/d/../../e"); | 506 testResolvePath("/a/b/e", "../a/b/c/d/../../e"); |
750 testResolvePath("/a/b/e", "./a/b/c/d/../../e"); | 507 testResolvePath("/a/b/e", "./a/b/c/d/../../e"); |
751 testResolvePath("/a/b/e", "../a/b/./c/d/../../e"); | 508 testResolvePath("/a/b/e", "../a/b/./c/d/../../e"); |
752 testResolvePath("/a/b/e", "./a/b/./c/d/../../e"); | 509 testResolvePath("/a/b/e", "./a/b/./c/d/../../e"); |
753 testResolvePath("/a/b/e/", "./a/b/./c/d/../../e/."); | 510 testResolvePath("/a/b/e/", "./a/b/./c/d/../../e/."); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 String dump(Uri uri) { | 638 String dump(Uri uri) { |
882 return "URI: $uri\n" | 639 return "URI: $uri\n" |
883 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 640 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
884 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 641 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
885 " Host: ${uri.host} #${uri.host.length}\n" | 642 " Host: ${uri.host} #${uri.host.length}\n" |
886 " Port: ${uri.port}\n" | 643 " Port: ${uri.port}\n" |
887 " Path: ${uri.path} #${uri.path.length}\n" | 644 " Path: ${uri.path} #${uri.path.length}\n" |
888 " Query: ${uri.query} #${uri.query.length}\n" | 645 " Query: ${uri.query} #${uri.query.length}\n" |
889 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 646 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
890 } | 647 } |
OLD | NEW |