Chromium Code Reviews| 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); | |
| 13 Expect.equals(isAbsolute, uri.isAbsolute); | 19 Expect.equals(isAbsolute, uri.isAbsolute); |
| 14 Expect.stringEquals(uriText, uri.toString()); | 20 Expect.stringEquals(uriText, uri.toString()); |
| 15 | 21 |
| 16 // Test equals and hashCode members. | 22 // Test equals and hashCode members. |
| 17 var uri2 = Uri.parse(uriText); | 23 var uri2 = Uri.parse(uriText); |
| 18 Expect.equals(uri, uri2); | 24 Expect.equals(uri, uri2); |
| 19 Expect.equals(uri.hashCode, uri2.hashCode); | 25 Expect.equals(uri.hashCode, uri2.hashCode); |
| 20 | 26 |
| 21 // Test that removeFragment doesn't change anything else. | 27 // Test that removeFragment doesn't change anything else. |
| 22 if (uri.hasFragment) { | 28 if (uri.hasFragment) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 testResolve("http://a/b/c/y", "g;x=1/../y"); | 126 testResolve("http://a/b/c/y", "g;x=1/../y"); |
| 121 testResolve("http://a/b/c/g?y/./x", "g?y/./x"); | 127 testResolve("http://a/b/c/g?y/./x", "g?y/./x"); |
| 122 testResolve("http://a/b/c/g?y/../x", "g?y/../x"); | 128 testResolve("http://a/b/c/g?y/../x", "g?y/../x"); |
| 123 testResolve("http://a/b/c/g#s/./x", "g#s/./x"); | 129 testResolve("http://a/b/c/g#s/./x", "g#s/./x"); |
| 124 testResolve("http://a/b/c/g#s/../x", "g#s/../x"); | 130 testResolve("http://a/b/c/g#s/../x", "g#s/../x"); |
| 125 testResolve("http:g", "http:g"); | 131 testResolve("http:g", "http:g"); |
| 126 | 132 |
| 127 // Additional tests (not from RFC 3986). | 133 // Additional tests (not from RFC 3986). |
| 128 testResolve("http://a/b/g;p/h;s", "../g;p/h;s"); | 134 testResolve("http://a/b/g;p/h;s", "../g;p/h;s"); |
| 129 | 135 |
| 136 base = Uri.parse("s:a/b"); | |
| 137 testResolve("s:a/c", "c"); | |
| 138 testResolve("s:/c", "../c"); | |
| 139 | |
| 140 base = Uri.parse("S:a/b"); | |
| 141 testResolve("s:a/c", "c"); | |
| 142 testResolve("s:/c", "../c"); | |
| 143 | |
| 144 base = Uri.parse("s:foo"); | |
| 145 testResolve("s:bar", "bar"); | |
| 146 testResolve("s:bar", "../bar"); | |
| 147 | |
| 148 base = Uri.parse("S:foo"); | |
| 149 testResolve("s:bar", "bar"); | |
| 150 testResolve("s:bar", "../bar"); | |
| 151 | |
| 152 base = Uri.parse("s:/foo"); | |
| 153 testResolve("s:/bar", "bar"); | |
| 154 testResolve("s:/bar", "../bar"); | |
| 155 | |
| 156 base = Uri.parse("S:/foo"); | |
| 157 testResolve("s:/bar", "bar"); | |
| 158 testResolve("s:/bar", "../bar"); | |
| 159 | |
| 130 // Test non-URI base (no scheme, no authority, relative path). | 160 // Test non-URI base (no scheme, no authority, relative path). |
| 131 base = Uri.parse("a/b/c?_#_"); | 161 base = Uri.parse("a/b/c?_#_"); |
| 132 testResolve("a/b/g?q#f", "g?q#f"); | 162 testResolve("a/b/g?q#f", "g?q#f"); |
| 133 testResolve("./", "../.."); | 163 testResolve("./", "../.."); |
| 134 testResolve("../", "../../.."); | 164 testResolve("../", "../../.."); |
| 135 testResolve("a/b/", "."); | 165 testResolve("a/b/", "."); |
| 136 testResolve("c", "../../c"); | 166 testResolve("/c", "../../c"); |
| 137 base = Uri.parse("../../a/b/c?_#_"); // Initial ".." in base url. | 167 base = Uri.parse("../../a/b/c?_#_"); // Initial ".." in base url. |
| 138 testResolve("../../a/d", "../d"); | 168 testResolve("../../a/d", "../d"); |
| 139 testResolve("../../../d", "../../../d"); | 169 testResolve("../../../d", "../../../d"); |
| 140 | 170 |
| 141 base = Uri.parse("s:a/b"); | 171 base = Uri.parse("s://h/p?q#f"); // A simple base. |
| 142 testResolve("s:/c", "../c"); | 172 // Simple references: |
| 173 testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F"); | |
| 174 testResolve("s://h2/P?Q#F", "//h2/P?Q#F"); | |
| 175 testResolve("s://h/P?Q#F", "/P?Q#F"); | |
| 176 testResolve("s://h/p?Q#F", "?Q#F"); | |
| 177 testResolve("s://h/p?q#F", "#F"); | |
| 178 testResolve("s://h/p?q", ""); | |
| 179 // Non-simple references: | |
| 180 testResolve("s2://I@h2/P?Q#F%20", "s2://I@h2/P?Q#F%20"); | |
| 181 testResolve("s://I@h2/P?Q#F%20", "//I@h2/P?Q#F%20"); | |
| 182 testResolve("s://h2/P?Q#F%20", "//h2/P?Q#F%20"); | |
| 183 testResolve("s://h/P?Q#F%20", "/P?Q#F%20"); | |
| 184 testResolve("s://h/p?Q#F%20", "?Q#F%20"); | |
| 185 testResolve("s://h/p?q#F%20", "#F%20"); | |
| 186 | |
| 187 base = Uri.parse("s://h/p1/p2/p3"); // A simple base with a path. | |
| 188 testResolve("s://h/p1/p2/", "."); | |
| 189 testResolve("s://h/p1/p2/", "./"); | |
| 190 testResolve("s://h/p1/", ".."); | |
| 191 testResolve("s://h/p1/", "../"); | |
| 192 testResolve("s://h/", "../.."); | |
| 193 testResolve("s://h/", "../../"); | |
| 194 testResolve("s://h/p1/%20", "../%20"); | |
| 195 testResolve("s://h/", "../../../.."); | |
| 196 testResolve("s://h/", "../../../../"); | |
| 197 | |
| 198 base = Uri.parse("s://h/p?q#f%20"); // A non-simpe base | |
|
floitsch
2016/06/29 23:41:48
finish with ".".
Lasse Reichstein Nielsen
2016/06/30 10:27:31
Argh, missed that one. Will fix.
| |
| 199 // Simple references: | |
| 200 testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F"); | |
| 201 testResolve("s://h2/P?Q#F", "//h2/P?Q#F"); | |
| 202 testResolve("s://h/P?Q#F", "/P?Q#F"); | |
| 203 testResolve("s://h/p?Q#F", "?Q#F"); | |
| 204 testResolve("s://h/p?q#F", "#F"); | |
| 205 testResolve("s://h/p?q", ""); | |
| 206 // Non-simple references: | |
| 207 testResolve("s2://I@h2/P?Q#F%20", "s2://I@h2/P?Q#F%20"); | |
| 208 testResolve("s://I@h2/P?Q#F%20", "//I@h2/P?Q#F%20"); | |
| 209 testResolve("s://h2/P?Q#F%20", "//h2/P?Q#F%20"); | |
| 210 testResolve("s://h/P?Q#F%20", "/P?Q#F%20"); | |
| 211 testResolve("s://h/p?Q#F%20", "?Q#F%20"); | |
| 212 testResolve("s://h/p?q#F%20", "#F%20"); | |
| 213 | |
| 214 base = Uri.parse("S://h/p1/p2/p3"); // A non-simple base with a path. | |
| 215 testResolve("s://h/p1/p2/", "."); | |
| 216 testResolve("s://h/p1/p2/", "./"); | |
| 217 testResolve("s://h/p1/", ".."); | |
| 218 testResolve("s://h/p1/", "../"); | |
| 219 testResolve("s://h/", "../.."); | |
| 220 testResolve("s://h/", "../../"); | |
| 221 testResolve("s://h/p1/%20", "../%20"); | |
| 222 testResolve("s://h/", "../../../.."); | |
| 223 testResolve("s://h/", "../../../../"); | |
| 224 | |
| 225 base = Uri.parse("../../../"); // A simple relative path. | |
| 226 testResolve("../../../a", "a"); | |
| 227 testResolve("../../../../a", "../a"); | |
| 228 testResolve("../../../a%20", "a%20"); | |
| 229 testResolve("../../../../a%20", "../a%20"); | |
| 230 | |
| 231 // Regression test. | |
| 232 base = Uri.parse("scheme:pathNoSlash"); | |
| 233 testResolve("scheme:otherPath", "otherPath"); | |
| 143 } | 234 } |
| 144 | 235 |
| 145 void testResolvePath(String expected, String path) { | 236 void testResolvePath(String expected, String path) { |
| 146 Expect.equals(expected, | 237 Expect.equals(expected, |
| 147 new Uri(path: '/').resolveUri(new Uri(path: path)).path); | 238 new Uri(path: '/').resolveUri(new Uri(path: path)).path); |
| 148 Expect.equals( | 239 Expect.equals( |
| 149 "http://localhost$expected", | 240 "http://localhost$expected", |
| 150 Uri.parse("http://localhost").resolveUri(new Uri(path: path)).toString()); | 241 Uri.parse("http://localhost").resolveUri(new Uri(path: path)).toString()); |
| 151 } | 242 } |
| 152 | 243 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 Expect.stringEquals("/a/b/c/", | 577 Expect.stringEquals("/a/b/c/", |
| 487 new Uri( | 578 new Uri( |
| 488 scheme: null, | 579 scheme: null, |
| 489 userInfo: null, | 580 userInfo: null, |
| 490 host: null, | 581 host: null, |
| 491 port: 0, | 582 port: 0, |
| 492 path: "/a/b/c/", | 583 path: "/a/b/c/", |
| 493 query: null, | 584 query: null, |
| 494 fragment: null).toString()); | 585 fragment: null).toString()); |
| 495 Expect.stringEquals("file:///", Uri.parse("file:").toString()); | 586 Expect.stringEquals("file:///", Uri.parse("file:").toString()); |
| 587 Expect.stringEquals("file:///", Uri.parse("file:/").toString()); | |
| 588 Expect.stringEquals("file:///", Uri.parse("file:").toString()); | |
| 589 Expect.stringEquals("file:///foo", Uri.parse("file:foo").toString()); | |
| 590 Expect.stringEquals("file:///foo", Uri.parse("file:/foo").toString()); | |
| 591 Expect.stringEquals("file://foo/", Uri.parse("file://foo").toString()); | |
| 496 | 592 |
| 497 testResolvePath("/a/g", "/a/b/c/./../../g"); | 593 testResolvePath("/a/g", "/a/b/c/./../../g"); |
| 498 testResolvePath("/a/g", "/a/b/c/./../../g"); | 594 testResolvePath("/a/g", "/a/b/c/./../../g"); |
| 499 testResolvePath("/mid/6", "mid/content=5/../6"); | 595 testResolvePath("/mid/6", "mid/content=5/../6"); |
| 500 testResolvePath("/a/b/e", "a/b/c/d/../../e"); | 596 testResolvePath("/a/b/e", "a/b/c/d/../../e"); |
| 501 testResolvePath("/a/b/e", "../a/b/c/d/../../e"); | 597 testResolvePath("/a/b/e", "../a/b/c/d/../../e"); |
| 502 testResolvePath("/a/b/e", "./a/b/c/d/../../e"); | 598 testResolvePath("/a/b/e", "./a/b/c/d/../../e"); |
| 503 testResolvePath("/a/b/e", "../a/b/./c/d/../../e"); | 599 testResolvePath("/a/b/e", "../a/b/./c/d/../../e"); |
| 504 testResolvePath("/a/b/e", "./a/b/./c/d/../../e"); | 600 testResolvePath("/a/b/e", "./a/b/./c/d/../../e"); |
| 505 testResolvePath("/a/b/e/", "./a/b/./c/d/../../e/."); | 601 testResolvePath("/a/b/e/", "./a/b/./c/d/../../e/."); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 String dump(Uri uri) { | 729 String dump(Uri uri) { |
| 634 return "URI: $uri\n" | 730 return "URI: $uri\n" |
| 635 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 731 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
| 636 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 732 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
| 637 " Host: ${uri.host} #${uri.host.length}\n" | 733 " Host: ${uri.host} #${uri.host.length}\n" |
| 638 " Port: ${uri.port}\n" | 734 " Port: ${uri.port}\n" |
| 639 " Path: ${uri.path} #${uri.path.length}\n" | 735 " Path: ${uri.path} #${uri.path.length}\n" |
| 640 " Query: ${uri.query} #${uri.query.length}\n" | 736 " Query: ${uri.query} #${uri.query.length}\n" |
| 641 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 737 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
| 642 } | 738 } |
| OLD | NEW |