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) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 Expect.stringEquals(encodedAscii, e); | 78 Expect.stringEquals(encodedAscii, e); |
79 d = Uri.decodeQueryComponent(encodedAscii, encoding: ASCII); | 79 d = Uri.decodeQueryComponent(encodedAscii, encoding: ASCII); |
80 Expect.stringEquals(orig, d); | 80 Expect.stringEquals(orig, d); |
81 } else { | 81 } else { |
82 Expect.throws(() => Uri.encodeQueryComponent(orig, encoding: ASCII), | 82 Expect.throws(() => Uri.encodeQueryComponent(orig, encoding: ASCII), |
83 (e) => e is ArgumentError); | 83 (e) => e is ArgumentError); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 testUriPerRFCs() { | 87 testUriPerRFCs() { |
88 final urisSample = "http://a/b/c/d;p?q"; | 88 // Convert a Uri to a guaranteed "non simple" URI with the same content. |
89 Uri base = Uri.parse(urisSample); | 89 toComplex(Uri uri) { |
| 90 Uri complex = new Uri( |
| 91 scheme: uri.scheme, |
| 92 userInfo: uri.hasAuthority ? uri.userInfo : null, |
| 93 host: uri.hasAuthority ? uri.host : null, |
| 94 port: uri.hasAuthority ? uri.port : null, |
| 95 path: uri.path, |
| 96 query: uri.hasQuery ? uri.query : null, |
| 97 fragment: uri.hasFragment ? uri.fragment : null, |
| 98 ); |
| 99 assert(complex.toString() == uri.toString()); |
| 100 return complex; |
| 101 } |
| 102 |
| 103 Uri base; |
| 104 Uri complexBase; |
| 105 // Sets the [base] and [complexBase] to the parse of the URI and a |
| 106 // guaranteed non-simple version of the same URI. |
| 107 setBase(String uri) { |
| 108 base = Uri.parse(uri); |
| 109 complexBase = toComplex(base); |
| 110 } |
| 111 |
90 testResolve(expect, relative) { | 112 testResolve(expect, relative) { |
91 String name = "$base << $relative"; | 113 String name = "$base << $relative"; |
92 Expect.stringEquals(expect, base.resolve(relative).toString(), name); | 114 Expect.stringEquals(expect, base.resolve(relative).toString(), name); |
| 115 |
| 116 Expect.stringEquals(expect, complexBase.resolve(relative).toString(), |
| 117 name + " (complex base)"); |
93 } | 118 } |
94 | 119 |
95 // From RFC 3986. | 120 // From RFC 3986. |
| 121 final urisSample = "http://a/b/c/d;p?q"; |
| 122 setBase(urisSample); |
| 123 |
96 testResolve("g:h", "g:h"); | 124 testResolve("g:h", "g:h"); |
97 testResolve("http://a/b/c/g", "g"); | 125 testResolve("http://a/b/c/g", "g"); |
98 testResolve("http://a/b/c/g", "./g"); | 126 testResolve("http://a/b/c/g", "./g"); |
99 testResolve("http://a/b/c/g/", "g/"); | 127 testResolve("http://a/b/c/g/", "g/"); |
100 testResolve("http://a/g", "/g"); | 128 testResolve("http://a/g", "/g"); |
101 testResolve("http://g", "//g"); | 129 testResolve("http://g", "//g"); |
102 testResolve("http://a/b/c/d;p?y", "?y"); | 130 testResolve("http://a/b/c/d;p?y", "?y"); |
103 testResolve("http://a/b/c/g?y", "g?y"); | 131 testResolve("http://a/b/c/g?y", "g?y"); |
104 testResolve("http://a/b/c/d;p?q#s", "#s"); | 132 testResolve("http://a/b/c/d;p?q#s", "#s"); |
105 testResolve("http://a/b/c/g#s", "g#s"); | 133 testResolve("http://a/b/c/g#s", "g#s"); |
(...skipping 26 matching lines...) Expand all Loading... |
132 testResolve("http://a/b/c/y", "g;x=1/../y"); | 160 testResolve("http://a/b/c/y", "g;x=1/../y"); |
133 testResolve("http://a/b/c/g?y/./x", "g?y/./x"); | 161 testResolve("http://a/b/c/g?y/./x", "g?y/./x"); |
134 testResolve("http://a/b/c/g?y/../x", "g?y/../x"); | 162 testResolve("http://a/b/c/g?y/../x", "g?y/../x"); |
135 testResolve("http://a/b/c/g#s/./x", "g#s/./x"); | 163 testResolve("http://a/b/c/g#s/./x", "g#s/./x"); |
136 testResolve("http://a/b/c/g#s/../x", "g#s/../x"); | 164 testResolve("http://a/b/c/g#s/../x", "g#s/../x"); |
137 testResolve("http:g", "http:g"); | 165 testResolve("http:g", "http:g"); |
138 | 166 |
139 // Additional tests (not from RFC 3986). | 167 // Additional tests (not from RFC 3986). |
140 testResolve("http://a/b/g;p/h;s", "../g;p/h;s"); | 168 testResolve("http://a/b/g;p/h;s", "../g;p/h;s"); |
141 | 169 |
142 base = Uri.parse("s:a/b"); | 170 setBase("s:a/b"); |
143 testResolve("s:a/c", "c"); | 171 testResolve("s:a/c", "c"); |
144 testResolve("s:/c", "../c"); | 172 testResolve("s:/c", "../c"); |
145 | 173 |
146 base = Uri.parse("S:a/b"); | 174 setBase("S:a/b"); |
147 testResolve("s:a/c", "c"); | 175 testResolve("s:a/c", "c"); |
148 testResolve("s:/c", "../c"); | 176 testResolve("s:/c", "../c"); |
149 | 177 |
150 base = Uri.parse("s:foo"); | 178 setBase("s:foo"); |
151 testResolve("s:bar", "bar"); | 179 testResolve("s:bar", "bar"); |
152 testResolve("s:bar", "../bar"); | 180 testResolve("s:bar", "../bar"); |
153 | 181 |
154 base = Uri.parse("S:foo"); | 182 setBase("S:foo"); |
155 testResolve("s:bar", "bar"); | 183 testResolve("s:bar", "bar"); |
156 testResolve("s:bar", "../bar"); | 184 testResolve("s:bar", "../bar"); |
157 | 185 |
158 // Special-case (deliberate non-RFC behavior). | 186 // Special-case (deliberate non-RFC behavior). |
159 base = Uri.parse("foo/bar"); | 187 setBase("foo/bar"); |
160 testResolve("foo/baz", "baz"); | 188 testResolve("foo/baz", "baz"); |
161 testResolve("baz", "../baz"); | 189 testResolve("baz", "../baz"); |
162 | 190 |
163 base = Uri.parse("s:/foo"); | 191 setBase("s:/foo"); |
164 testResolve("s:/bar", "bar"); | 192 testResolve("s:/bar", "bar"); |
165 testResolve("s:/bar", "../bar"); | 193 testResolve("s:/bar", "../bar"); |
166 | 194 |
167 base = Uri.parse("S:/foo"); | 195 setBase("S:/foo"); |
168 testResolve("s:/bar", "bar"); | 196 testResolve("s:/bar", "bar"); |
169 testResolve("s:/bar", "../bar"); | 197 testResolve("s:/bar", "../bar"); |
170 | 198 |
171 // Test non-URI base (no scheme, no authority, relative path). | 199 // Test non-URI base (no scheme, no authority, relative path). |
172 base = Uri.parse("a/b/c?_#_"); | 200 setBase("a/b/c?_#_"); |
173 testResolve("a/b/g?q#f", "g?q#f"); | 201 testResolve("a/b/g?q#f", "g?q#f"); |
174 testResolve("./", "../.."); | 202 testResolve("./", "../.."); |
175 testResolve("../", "../../.."); | 203 testResolve("../", "../../.."); |
176 testResolve("a/b/", "."); | 204 testResolve("a/b/", "."); |
177 testResolve("c", "../../c"); // Deliberate non-RFC behavior. | 205 testResolve("c", "../../c"); // Deliberate non-RFC behavior. |
178 base = Uri.parse("../../a/b/c?_#_"); // Initial ".." in base url. | 206 setBase("../../a/b/c?_#_"); // Initial ".." in base url. |
179 testResolve("../../a/d", "../d"); | 207 testResolve("../../a/d", "../d"); |
| 208 testResolve("../../d", "../../d"); |
180 testResolve("../../../d", "../../../d"); | 209 testResolve("../../../d", "../../../d"); |
| 210 setBase("../../a/b"); |
| 211 testResolve("../../a/d", "d"); |
| 212 testResolve("../../d", "../d"); |
| 213 testResolve("../../../d", "../../d"); |
| 214 setBase("../../a"); |
| 215 testResolve("../../d", "d"); |
| 216 testResolve("../../../d", "../d"); |
| 217 testResolve("../../../../d", "../../d"); |
181 | 218 |
182 base = Uri.parse("s://h/p?q#f"); // A simple base. | 219 // Absoluyte path, not scheme or authority. |
| 220 setBase("/a"); |
| 221 testResolve("/b", "b"); |
| 222 testResolve("/b", "../b"); |
| 223 testResolve("/b", "../../b"); |
| 224 setBase("/a/b"); |
| 225 testResolve("/a/c", "c"); |
| 226 testResolve("/c", "../c"); |
| 227 testResolve("/c", "../../c"); |
| 228 |
| 229 setBase("s://h/p?q#f"); // A simple base. |
183 // Simple references: | 230 // Simple references: |
184 testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F"); | 231 testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F"); |
185 testResolve("s://h2/P?Q#F", "//h2/P?Q#F"); | 232 testResolve("s://h2/P?Q#F", "//h2/P?Q#F"); |
186 testResolve("s://h/P?Q#F", "/P?Q#F"); | 233 testResolve("s://h/P?Q#F", "/P?Q#F"); |
187 testResolve("s://h/p?Q#F", "?Q#F"); | 234 testResolve("s://h/p?Q#F", "?Q#F"); |
188 testResolve("s://h/p?q#F", "#F"); | 235 testResolve("s://h/p?q#F", "#F"); |
189 testResolve("s://h/p?q", ""); | 236 testResolve("s://h/p?q", ""); |
190 // Non-simple references: | 237 // Non-simple references: |
191 testResolve("s2://I@h2/P?Q#F%20", "s2://I@h2/P?Q#F%20"); | 238 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"); | 239 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"); | 240 testResolve("s://h2/P?Q#F%20", "//h2/P?Q#F%20"); |
194 testResolve("s://h/P?Q#F%20", "/P?Q#F%20"); | 241 testResolve("s://h/P?Q#F%20", "/P?Q#F%20"); |
195 testResolve("s://h/p?Q#F%20", "?Q#F%20"); | 242 testResolve("s://h/p?Q#F%20", "?Q#F%20"); |
196 testResolve("s://h/p?q#F%20", "#F%20"); | 243 testResolve("s://h/p?q#F%20", "#F%20"); |
197 | 244 |
198 base = Uri.parse("s://h/p1/p2/p3"); // A simple base with a path. | 245 setBase("s://h/p1/p2/p3"); // A simple base with a path. |
199 testResolve("s://h/p1/p2/", "."); | 246 testResolve("s://h/p1/p2/", "."); |
200 testResolve("s://h/p1/p2/", "./"); | 247 testResolve("s://h/p1/p2/", "./"); |
201 testResolve("s://h/p1/", ".."); | 248 testResolve("s://h/p1/", ".."); |
202 testResolve("s://h/p1/", "../"); | 249 testResolve("s://h/p1/", "../"); |
203 testResolve("s://h/", "../.."); | 250 testResolve("s://h/", "../.."); |
204 testResolve("s://h/", "../../"); | 251 testResolve("s://h/", "../../"); |
205 testResolve("s://h/p1/%20", "../%20"); | 252 testResolve("s://h/p1/%20", "../%20"); |
206 testResolve("s://h/", "../../../.."); | 253 testResolve("s://h/", "../../../.."); |
207 testResolve("s://h/", "../../../../"); | 254 testResolve("s://h/", "../../../../"); |
208 | 255 |
209 base = Uri.parse("s://h/p?q#f%20"); // A non-simpe base. | 256 setBase("s://h/p?q#f%20"); // A non-simpe base. |
210 // Simple references: | 257 // Simple references: |
211 testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F"); | 258 testResolve("s2://h2/P?Q#F", "s2://h2/P?Q#F"); |
212 testResolve("s://h2/P?Q#F", "//h2/P?Q#F"); | 259 testResolve("s://h2/P?Q#F", "//h2/P?Q#F"); |
213 testResolve("s://h/P?Q#F", "/P?Q#F"); | 260 testResolve("s://h/P?Q#F", "/P?Q#F"); |
214 testResolve("s://h/p?Q#F", "?Q#F"); | 261 testResolve("s://h/p?Q#F", "?Q#F"); |
215 testResolve("s://h/p?q#F", "#F"); | 262 testResolve("s://h/p?q#F", "#F"); |
216 testResolve("s://h/p?q", ""); | 263 testResolve("s://h/p?q", ""); |
217 // Non-simple references: | 264 // Non-simple references: |
218 testResolve("s2://I@h2/P?Q#F%20", "s2://I@h2/P?Q#F%20"); | 265 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"); | 266 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"); | 267 testResolve("s://h2/P?Q#F%20", "//h2/P?Q#F%20"); |
221 testResolve("s://h/P?Q#F%20", "/P?Q#F%20"); | 268 testResolve("s://h/P?Q#F%20", "/P?Q#F%20"); |
222 testResolve("s://h/p?Q#F%20", "?Q#F%20"); | 269 testResolve("s://h/p?Q#F%20", "?Q#F%20"); |
223 testResolve("s://h/p?q#F%20", "#F%20"); | 270 testResolve("s://h/p?q#F%20", "#F%20"); |
224 | 271 |
225 base = Uri.parse("S://h/p1/p2/p3"); // A non-simple base with a path. | 272 setBase("S://h/p1/p2/p3"); // A non-simple base with a path. |
226 testResolve("s://h/p1/p2/", "."); | 273 testResolve("s://h/p1/p2/", "."); |
227 testResolve("s://h/p1/p2/", "./"); | 274 testResolve("s://h/p1/p2/", "./"); |
228 testResolve("s://h/p1/", ".."); | 275 testResolve("s://h/p1/", ".."); |
229 testResolve("s://h/p1/", "../"); | 276 testResolve("s://h/p1/", "../"); |
230 testResolve("s://h/", "../.."); | 277 testResolve("s://h/", "../.."); |
231 testResolve("s://h/", "../../"); | 278 testResolve("s://h/", "../../"); |
232 testResolve("s://h/p1/%20", "../%20"); | 279 testResolve("s://h/p1/%20", "../%20"); |
233 testResolve("s://h/", "../../../.."); | 280 testResolve("s://h/", "../../../.."); |
234 testResolve("s://h/", "../../../../"); | 281 testResolve("s://h/", "../../../../"); |
235 | 282 |
236 base = Uri.parse("../../../"); // A simple relative path. | 283 setBase("../../../"); // A simple relative path. |
237 testResolve("../../../a", "a"); | 284 testResolve("../../../a", "a"); |
238 testResolve("../../../../a", "../a"); | 285 testResolve("../../../../a", "../a"); |
239 testResolve("../../../a%20", "a%20"); | 286 testResolve("../../../a%20", "a%20"); |
240 testResolve("../../../../a%20", "../a%20"); | 287 testResolve("../../../../a%20", "../a%20"); |
241 | 288 |
242 // Tests covering the branches of the merge algorithm in RFC 3986 | 289 // Tests covering the branches of the merge algorithm in RFC 3986 |
243 // with both simple and complex base URIs. | 290 // 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"]) { | 291 for (var b in ["s://a/pa/pb?q#f", "s://a/pa/pb?q#f%20"]) { |
245 var origBase = Uri.parse(b); | 292 setBase(b); |
246 base = origBase; | |
247 | 293 |
248 // if defined(R.scheme) then ... | 294 // if defined(R.scheme) then ... |
249 testResolve("s2://a2/p2?q2#f2", "s2://a2/p2?q2#f2"); | 295 testResolve("s2://a2/p2?q2#f2", "s2://a2/p2?q2#f2"); |
250 // else, if defined(R.authority) then ... | 296 // else, if defined(R.authority) then ... |
251 testResolve("s://a2/p2?q2#f2", "//a2/p2?q2#f2"); | 297 testResolve("s://a2/p2?q2#f2", "//a2/p2?q2#f2"); |
252 testResolve("s://a2/?q2#f2", "//a2/../?q2#f2"); | 298 testResolve("s://a2/?q2#f2", "//a2/../?q2#f2"); |
253 testResolve("s://a2?q2#f2", "//a2?q2#f2"); | 299 testResolve("s://a2?q2#f2", "//a2?q2#f2"); |
254 testResolve("s://a2#f2", "//a2#f2"); | 300 testResolve("s://a2#f2", "//a2#f2"); |
255 testResolve("s://a2", "//a2"); | 301 testResolve("s://a2", "//a2"); |
256 // else, if (R.path == "") then ... | 302 // else, if (R.path == "") then ... |
257 // if defined(R.query) then | 303 // if defined(R.query) then |
258 testResolve("s://a/pa/pb?q2#f2", "?q2#f2"); | 304 testResolve("s://a/pa/pb?q2#f2", "?q2#f2"); |
259 testResolve("s://a/pa/pb?q2", "?q2"); | 305 testResolve("s://a/pa/pb?q2", "?q2"); |
260 // else | 306 // else |
261 testResolve("s://a/pa/pb?q#f2", "#f2"); | 307 testResolve("s://a/pa/pb?q#f2", "#f2"); |
262 testResolve("s://a/pa/pb?q", ""); | 308 testResolve("s://a/pa/pb?q", ""); |
263 // else, if (R.path starts-with "/") then ... | 309 // else, if (R.path starts-with "/") then ... |
264 testResolve("s://a/p2?q2#f2", "/p2?q2#f2"); | 310 testResolve("s://a/p2?q2#f2", "/p2?q2#f2"); |
265 testResolve("s://a/?q2#f2", "/?q2#f2"); | 311 testResolve("s://a/?q2#f2", "/?q2#f2"); |
266 testResolve("s://a/#f2", "/#f2"); | 312 testResolve("s://a/#f2", "/#f2"); |
267 testResolve("s://a/", "/"); | 313 testResolve("s://a/", "/"); |
268 testResolve("s://a/", "/../"); | 314 testResolve("s://a/", "/../"); |
269 // else ... T.path = merge(Base.path, R.path) | 315 // else ... T.path = merge(Base.path, R.path) |
270 // ... remove-dot-fragments(T.path) ... | 316 // ... remove-dot-fragments(T.path) ... |
271 // (Cover the merge function and the remove-dot-fragments functions too). | 317 // (Cover the merge function and the remove-dot-fragments functions too). |
272 | 318 |
273 // If base has authority and empty path ... | 319 // If base has authority and empty path ... |
274 var emptyPathBase = Uri.parse(b.replaceFirst("/pa/pb", "")); | 320 var emptyPathBase = b.replaceFirst("/pa/pb", ""); |
275 base = emptyPathBase; | 321 setBase(emptyPathBase); |
276 testResolve("s://a/p2?q2#f2", "p2?q2#f2"); | 322 testResolve("s://a/p2?q2#f2", "p2?q2#f2"); |
277 testResolve("s://a/p2#f2", "p2#f2"); | 323 testResolve("s://a/p2#f2", "p2#f2"); |
278 testResolve("s://a/p2", "p2"); | 324 testResolve("s://a/p2", "p2"); |
279 | 325 |
280 base = origBase; | 326 setBase(b); |
281 // otherwise | 327 // otherwise |
282 // (Cover both no authority and non-empty path and both). | 328 // (Cover both no authority and non-empty path and both). |
283 var noAuthEmptyPathBase = Uri.parse(b.replaceFirst("//a/pa/pb", "")); | 329 var noAuthEmptyPathBase = b.replaceFirst("//a/pa/pb", ""); |
284 var noAuthAbsPathBase = Uri.parse(b.replaceFirst("//a", "")); | 330 var noAuthAbsPathBase = b.replaceFirst("//a", ""); |
285 var noAuthRelPathBase = Uri.parse(b.replaceFirst("//a/", "")); | 331 var noAuthRelPathBase = b.replaceFirst("//a/", ""); |
286 var noAuthRelSinglePathBase = Uri.parse(b.replaceFirst("//a/pa/", "")); | 332 var noAuthRelSinglePathBase = b.replaceFirst("//a/pa/", ""); |
287 | 333 |
288 testResolve("s://a/pa/p2?q2#f2", "p2?q2#f2"); | 334 testResolve("s://a/pa/p2?q2#f2", "p2?q2#f2"); |
289 testResolve("s://a/pa/p2#f2", "p2#f2"); | 335 testResolve("s://a/pa/p2#f2", "p2#f2"); |
290 testResolve("s://a/pa/p2", "p2"); | 336 testResolve("s://a/pa/p2", "p2"); |
291 | 337 |
292 base = noAuthEmptyPathBase; | 338 setBase(noAuthEmptyPathBase); |
293 testResolve("s:p2?q2#f2", "p2?q2#f2"); | 339 testResolve("s:p2?q2#f2", "p2?q2#f2"); |
294 testResolve("s:p2#f2", "p2#f2"); | 340 testResolve("s:p2#f2", "p2#f2"); |
295 testResolve("s:p2", "p2"); | 341 testResolve("s:p2", "p2"); |
296 | 342 |
297 base = noAuthAbsPathBase; | 343 setBase(noAuthAbsPathBase); |
298 testResolve("s:/pa/p2?q2#f2", "p2?q2#f2"); | 344 testResolve("s:/pa/p2?q2#f2", "p2?q2#f2"); |
299 testResolve("s:/pa/p2#f2", "p2#f2"); | 345 testResolve("s:/pa/p2#f2", "p2#f2"); |
300 testResolve("s:/pa/p2", "p2"); | 346 testResolve("s:/pa/p2", "p2"); |
301 | 347 |
302 base = noAuthRelPathBase; | 348 setBase(noAuthRelPathBase); |
303 testResolve("s:pa/p2?q2#f2", "p2?q2#f2"); | 349 testResolve("s:pa/p2?q2#f2", "p2?q2#f2"); |
304 testResolve("s:pa/p2#f2", "p2#f2"); | 350 testResolve("s:pa/p2#f2", "p2#f2"); |
305 testResolve("s:pa/p2", "p2"); | 351 testResolve("s:pa/p2", "p2"); |
306 | 352 |
307 base = noAuthRelSinglePathBase; | 353 setBase(noAuthRelSinglePathBase); |
308 testResolve("s:p2?q2#f2", "p2?q2#f2"); | 354 testResolve("s:p2?q2#f2", "p2?q2#f2"); |
309 testResolve("s:p2#f2", "p2#f2"); | 355 testResolve("s:p2#f2", "p2#f2"); |
310 testResolve("s:p2", "p2"); | 356 testResolve("s:p2", "p2"); |
311 | 357 |
312 // Then remove dot segments. | 358 // Then remove dot segments. |
313 | 359 |
314 // A. if input buffer starts with "../" or "./". | 360 // A. if input buffer starts with "../" or "./". |
315 // This only happens if base has only a single (may be empty) segment and | 361 // This only happens if base has only a single (may be empty) segment and |
316 // no slash. | 362 // no slash. |
317 base = emptyPathBase; | 363 setBase(emptyPathBase); |
318 testResolve("s://a/p2", "../p2"); | 364 testResolve("s://a/p2", "../p2"); |
319 testResolve("s://a/", "../"); | 365 testResolve("s://a/", "../"); |
320 testResolve("s://a/", ".."); | 366 testResolve("s://a/", ".."); |
321 testResolve("s://a/p2", "./p2"); | 367 testResolve("s://a/p2", "./p2"); |
322 testResolve("s://a/", "./"); | 368 testResolve("s://a/", "./"); |
323 testResolve("s://a/", "."); | 369 testResolve("s://a/", "."); |
324 testResolve("s://a/p2", "../../p2"); | 370 testResolve("s://a/p2", "../../p2"); |
325 testResolve("s://a/p2", "../../././p2"); | 371 testResolve("s://a/p2", "../../././p2"); |
326 | 372 |
327 base = noAuthRelSinglePathBase; | 373 setBase(noAuthRelSinglePathBase); |
328 testResolve("s:p2", "../p2"); | 374 testResolve("s:p2", "../p2"); |
329 testResolve("s:", "../"); | 375 testResolve("s:", "../"); |
330 testResolve("s:", ".."); | 376 testResolve("s:", ".."); |
331 testResolve("s:p2", "./p2"); | 377 testResolve("s:p2", "./p2"); |
332 testResolve("s:", "./"); | 378 testResolve("s:", "./"); |
333 testResolve("s:", "."); | 379 testResolve("s:", "."); |
334 testResolve("s:p2", "../../p2"); | 380 testResolve("s:p2", "../../p2"); |
335 testResolve("s:p2", "../../././p2"); | 381 testResolve("s:p2", "../../././p2"); |
336 | 382 |
337 // B. if input buffer starts with "/./" or is "/.". replace with "/". | 383 // B. if input buffer starts with "/./" or is "/.". replace with "/". |
338 // (The URI implementation removes the "." path segments when parsing, | 384 // (The URI implementation removes the "." path segments when parsing, |
339 // so this case isn't handled by merge). | 385 // so this case isn't handled by merge). |
340 base = origBase; | 386 setBase(b); |
341 testResolve("s://a/pa/p2", "./p2"); | 387 testResolve("s://a/pa/p2", "./p2"); |
342 | 388 |
343 // C. if input buffer starts with "/../" or is "/..", replace with "/" | 389 // C. if input buffer starts with "/../" or is "/..", replace with "/" |
344 // and remove preceeding segment. | 390 // and remove preceeding segment. |
345 testResolve("s://a/p2", "../p2"); | 391 testResolve("s://a/p2", "../p2"); |
346 var longPathBase = Uri.parse(b.replaceFirst("/pb", "/pb/pc/pd")); | 392 var longPathBase = b.replaceFirst("/pb", "/pb/pc/pd"); |
347 base = longPathBase; | 393 setBase(longPathBase); |
348 testResolve("s://a/pa/pb/p2", "../p2"); | 394 testResolve("s://a/pa/pb/p2", "../p2"); |
349 testResolve("s://a/pa/p2", "../../p2"); | 395 testResolve("s://a/pa/p2", "../../p2"); |
350 testResolve("s://a/p2", "../../../p2"); | 396 testResolve("s://a/p2", "../../../p2"); |
351 testResolve("s://a/p2", "../../../../p2"); | 397 testResolve("s://a/p2", "../../../../p2"); |
352 var noAuthRelLongPathBase = | 398 var noAuthRelLongPathBase = b.replaceFirst("//a/pa/pb", "pa/pb/pc/pd"); |
353 Uri.parse(b.replaceFirst("//a/pa/pb", "pa/pb/pc/pd")); | 399 setBase(noAuthRelLongPathBase); |
354 base = noAuthRelLongPathBase; | |
355 testResolve("s:pa/pb/p2", "../p2"); | 400 testResolve("s:pa/pb/p2", "../p2"); |
356 testResolve("s:pa/p2", "../../p2"); | 401 testResolve("s:pa/p2", "../../p2"); |
357 testResolve("s:/p2", "../../../p2"); | 402 testResolve("s:/p2", "../../../p2"); |
358 testResolve("s:/p2", "../../../../p2"); | 403 testResolve("s:/p2", "../../../../p2"); |
359 | 404 |
360 // D. if the input buffer contains only ".." or ".", remove it. | 405 // D. if the input buffer contains only ".." or ".", remove it. |
361 base = noAuthEmptyPathBase; | 406 setBase(noAuthEmptyPathBase); |
362 testResolve("s:", ".."); | 407 testResolve("s:", ".."); |
363 testResolve("s:", "."); | 408 testResolve("s:", "."); |
364 base = noAuthRelSinglePathBase; | 409 setBase(noAuthRelSinglePathBase); |
365 testResolve("s:", ".."); | 410 testResolve("s:", ".."); |
366 testResolve("s:", "."); | 411 testResolve("s:", "."); |
367 } | 412 } |
368 } | 413 } |
369 | 414 |
370 void testResolvePath(String expected, String path) { | 415 void testResolvePath(String expected, String path) { |
371 Expect.equals(expected, | 416 Expect.equals(expected, |
372 new Uri(path: '/').resolveUri(new Uri(path: path)).path); | 417 new Uri(path: '/').resolveUri(new Uri(path: path)).path); |
373 Expect.equals( | 418 Expect.equals( |
374 "http://localhost$expected", | 419 "http://localhost$expected", |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 String dump(Uri uri) { | 926 String dump(Uri uri) { |
882 return "URI: $uri\n" | 927 return "URI: $uri\n" |
883 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 928 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
884 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 929 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
885 " Host: ${uri.host} #${uri.host.length}\n" | 930 " Host: ${uri.host} #${uri.host.length}\n" |
886 " Port: ${uri.port}\n" | 931 " Port: ${uri.port}\n" |
887 " Path: ${uri.path} #${uri.path.length}\n" | 932 " Path: ${uri.path} #${uri.path.length}\n" |
888 " Query: ${uri.query} #${uri.query.length}\n" | 933 " Query: ${uri.query} #${uri.query.length}\n" |
889 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 934 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
890 } | 935 } |
OLD | NEW |