Flutter Engine
The Flutter Engine
uri_test.cc
Go to the documentation of this file.
1// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
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.
4
5#include "vm/unit_test.h"
6
7#include "platform/uri.h"
8#include "platform/utils.h"
9
10namespace dart {
11
12#define EXPECT_USTREQ(expected, actual) EXPECT_STREQ(expected, actual.get())
13
14TEST_CASE(ParseUri_WithScheme_NoQueryNoUser) {
15 auto uri = ParseUri("foo://example.com:8042/over/there");
16 EXPECT(uri);
17 EXPECT_USTREQ("foo", uri->scheme);
18 EXPECT(uri->userinfo == nullptr);
19 EXPECT_USTREQ("example.com", uri->host);
20 EXPECT_USTREQ("8042", uri->port);
21 EXPECT_USTREQ("/over/there", uri->path);
22 EXPECT(uri->query == nullptr);
23 EXPECT(uri->fragment == nullptr);
24}
25
26TEST_CASE(ParseUri_WithScheme_WithQuery) {
27 auto uri = ParseUri("foo://example.com:8042/over/there?name=ferret");
28 EXPECT(uri);
29 EXPECT_USTREQ("foo", uri->scheme);
30 EXPECT(uri->userinfo == nullptr);
31 EXPECT_USTREQ("example.com", uri->host);
32 EXPECT_USTREQ("8042", uri->port);
33 EXPECT_USTREQ("/over/there", uri->path);
34 EXPECT_USTREQ("name=ferret", uri->query);
35 EXPECT(uri->fragment == nullptr);
36}
37
38TEST_CASE(ParseUri_WithScheme_WithFragment) {
39 auto uri = ParseUri("foo://example.com:8042/over/there#fragment");
40 EXPECT(uri);
41 EXPECT_USTREQ("foo", uri->scheme);
42 EXPECT(uri->userinfo == nullptr);
43 EXPECT_USTREQ("example.com", uri->host);
44 EXPECT_USTREQ("8042", uri->port);
45 EXPECT_USTREQ("/over/there", uri->path);
46 EXPECT(uri->query == nullptr);
47 EXPECT_USTREQ("fragment", uri->fragment);
48}
49
50TEST_CASE(ParseUri_WithScheme_WithQueryWithFragment) {
51 auto uri = ParseUri("foo://example.com:8042/over/there?name=ferret#fragment");
52 EXPECT(uri);
53 EXPECT_USTREQ("foo", uri->scheme);
54 EXPECT(uri->userinfo == nullptr);
55 EXPECT_USTREQ("example.com", uri->host);
56 EXPECT_USTREQ("8042", uri->port);
57 EXPECT_USTREQ("/over/there", uri->path);
58 EXPECT_USTREQ("name=ferret", uri->query);
59 EXPECT_USTREQ("fragment", uri->fragment);
60}
61
62TEST_CASE(ParseUri_WithScheme_WithUser) {
63 auto uri = ParseUri("foo://user@example.com:8042/over/there");
64 EXPECT(uri);
65 EXPECT_USTREQ("foo", uri->scheme);
66 EXPECT_USTREQ("user", uri->userinfo);
67 EXPECT_USTREQ("example.com", uri->host);
68 EXPECT_USTREQ("8042", uri->port);
69 EXPECT_USTREQ("/over/there", uri->path);
70 EXPECT(uri->query == nullptr);
71 EXPECT(uri->fragment == nullptr);
72}
73
74TEST_CASE(ParseUri_WithScheme_ShortPath) {
75 auto uri = ParseUri("foo://example.com:8042/");
76 EXPECT(uri);
77 EXPECT_USTREQ("foo", uri->scheme);
78 EXPECT(uri->userinfo == nullptr);
79 EXPECT_USTREQ("example.com", uri->host);
80 EXPECT_USTREQ("8042", uri->port);
81 EXPECT_USTREQ("/", uri->path);
82 EXPECT(uri->query == nullptr);
83 EXPECT(uri->fragment == nullptr);
84}
85
86TEST_CASE(ParseUri_WithScheme_EmptyPath) {
87 auto uri = ParseUri("foo://example.com:8042");
88 EXPECT(uri);
89 EXPECT_USTREQ("foo", uri->scheme);
90 EXPECT(uri->userinfo == nullptr);
91 EXPECT_USTREQ("example.com", uri->host);
92 EXPECT_USTREQ("8042", uri->port);
93 EXPECT_USTREQ("", uri->path);
94 EXPECT(uri->query == nullptr);
95 EXPECT(uri->fragment == nullptr);
96}
97
98TEST_CASE(ParseUri_WithScheme_Rootless1) {
99 auto uri = ParseUri("foo:here");
100 EXPECT(uri);
101 EXPECT_USTREQ("foo", uri->scheme);
102 EXPECT(uri->userinfo == nullptr);
103 EXPECT(uri->host == nullptr);
104 EXPECT(uri->port == nullptr);
105 EXPECT_USTREQ("here", uri->path);
106 EXPECT(uri->query == nullptr);
107 EXPECT(uri->fragment == nullptr);
108}
109
110TEST_CASE(ParseUri_WithScheme_Rootless2) {
111 auto uri = ParseUri("foo:or/here");
112 EXPECT(uri);
113 EXPECT_USTREQ("foo", uri->scheme);
114 EXPECT(uri->userinfo == nullptr);
115 EXPECT(uri->host == nullptr);
116 EXPECT(uri->port == nullptr);
117 EXPECT_USTREQ("or/here", uri->path);
118 EXPECT(uri->query == nullptr);
119 EXPECT(uri->fragment == nullptr);
120}
121
122TEST_CASE(ParseUri_NoScheme_AbsPath_WithAuthority) {
123 auto uri = ParseUri("//example.com:8042/over/there");
124 EXPECT(uri);
125 EXPECT(uri->scheme == nullptr);
126 EXPECT(uri->userinfo == nullptr);
127 EXPECT_USTREQ("example.com", uri->host);
128 EXPECT_USTREQ("8042", uri->port);
129 EXPECT_USTREQ("/over/there", uri->path);
130 EXPECT(uri->query == nullptr);
131 EXPECT(uri->fragment == nullptr);
132}
133
134TEST_CASE(ParseUri_NoScheme_AbsPath_NoAuthority) {
135 auto uri = ParseUri("/over/there");
136 EXPECT(uri);
137 EXPECT(uri->scheme == nullptr);
138 EXPECT(uri->userinfo == nullptr);
139 EXPECT(uri->host == nullptr);
140 EXPECT(uri->port == nullptr);
141 EXPECT_USTREQ("/over/there", uri->path);
142 EXPECT(uri->query == nullptr);
143 EXPECT(uri->fragment == nullptr);
144}
145
146// Colons are permitted in path segments, in many cases.
147TEST_CASE(ParseUri_NoScheme_AbsPath_StrayColon) {
148 auto uri = ParseUri("/ov:er/there");
149 EXPECT(uri);
150 EXPECT(uri->scheme == nullptr);
151 EXPECT(uri->userinfo == nullptr);
152 EXPECT(uri->host == nullptr);
153 EXPECT(uri->port == nullptr);
154 EXPECT_USTREQ("/ov:er/there", uri->path);
155 EXPECT(uri->query == nullptr);
156}
157
158TEST_CASE(ParseUri_NoScheme_Rootless1) {
159 auto uri = ParseUri("here");
160 EXPECT(uri);
161 EXPECT(uri->scheme == nullptr);
162 EXPECT(uri->userinfo == nullptr);
163 EXPECT(uri->host == nullptr);
164 EXPECT(uri->port == nullptr);
165 EXPECT_USTREQ("here", uri->path);
166 EXPECT(uri->query == nullptr);
167 EXPECT(uri->fragment == nullptr);
168}
169
170TEST_CASE(ParseUri_NoScheme_Rootless2) {
171 auto uri = ParseUri("or/here");
172 EXPECT(uri);
173 EXPECT(uri->scheme == nullptr);
174 EXPECT(uri->userinfo == nullptr);
175 EXPECT(uri->host == nullptr);
176 EXPECT(uri->port == nullptr);
177 EXPECT_USTREQ("or/here", uri->path);
178 EXPECT(uri->query == nullptr);
179 EXPECT(uri->fragment == nullptr);
180}
181
182TEST_CASE(ParseUri_NoScheme_Empty) {
183 auto uri = ParseUri("");
184 EXPECT(uri);
185 EXPECT(uri->scheme == nullptr);
186 EXPECT(uri->userinfo == nullptr);
187 EXPECT(uri->host == nullptr);
188 EXPECT(uri->port == nullptr);
189 EXPECT_USTREQ("", uri->path);
190 EXPECT(uri->query == nullptr);
191 EXPECT(uri->fragment == nullptr);
192}
193
194TEST_CASE(ParseUri_NoScheme_QueryOnly) {
195 auto uri = ParseUri("?name=ferret");
196 EXPECT(uri);
197 EXPECT(uri->scheme == nullptr);
198 EXPECT(uri->userinfo == nullptr);
199 EXPECT(uri->host == nullptr);
200 EXPECT(uri->port == nullptr);
201 EXPECT_USTREQ("", uri->path);
202 EXPECT_USTREQ("name=ferret", uri->query);
203 EXPECT(uri->fragment == nullptr);
204}
205
206TEST_CASE(ParseUri_NoScheme_FragmentOnly) {
207 auto uri = ParseUri("#fragment");
208 EXPECT(uri);
209 EXPECT(uri->scheme == nullptr);
210 EXPECT(uri->userinfo == nullptr);
211 EXPECT(uri->host == nullptr);
212 EXPECT(uri->port == nullptr);
213 EXPECT_USTREQ("", uri->path);
214 EXPECT(uri->query == nullptr);
215 EXPECT_USTREQ("fragment", uri->fragment);
216}
217
218TEST_CASE(ParseUri_LowerCaseScheme) {
219 auto uri = ParseUri("ScHeMe:path");
220 EXPECT(uri);
221 EXPECT_USTREQ("scheme", uri->scheme);
222 EXPECT(uri->userinfo == nullptr);
223 EXPECT(uri->host == nullptr);
224 EXPECT(uri->port == nullptr);
225 EXPECT_USTREQ("path", uri->path);
226 EXPECT(uri->query == nullptr);
227 EXPECT(uri->fragment == nullptr);
228}
229
230TEST_CASE(ParseUri_NormalizeEscapes_PathQueryFragment) {
231 auto uri =
232 ParseUri("scheme:/This%09Is A P%61th?This%09Is A Qu%65ry#A Fr%61gment");
233 EXPECT(uri);
234 EXPECT_USTREQ("scheme", uri->scheme);
235 EXPECT(uri->userinfo == nullptr);
236 EXPECT(uri->host == nullptr);
237 EXPECT(uri->port == nullptr);
238 EXPECT_USTREQ("/This%09Is%20A%20Path", uri->path);
239 EXPECT_USTREQ("This%09Is%20A%20Query", uri->query);
240 EXPECT_USTREQ("A%20Fragment", uri->fragment);
241}
242
243TEST_CASE(ParseUri_NormalizeEscapes_UppercaseEscapesPreferred) {
244 auto uri = ParseUri("scheme:/%1b%1B");
245 EXPECT(uri);
246 EXPECT_USTREQ("scheme", uri->scheme);
247 EXPECT(uri->userinfo == nullptr);
248 EXPECT(uri->host == nullptr);
249 EXPECT(uri->port == nullptr);
250 EXPECT_USTREQ("/%1B%1B", uri->path);
251 EXPECT(uri->query == nullptr);
252 EXPECT(uri->fragment == nullptr);
253}
254
255TEST_CASE(ParseUri_NormalizeEscapes_Authority) {
256 auto uri = ParseUri("scheme://UsEr N%61%4de@h%4FsT.c%6fm:80/");
257 EXPECT(uri);
258 EXPECT_USTREQ("scheme", uri->scheme);
259 EXPECT_USTREQ("UsEr%20NaMe", uri->userinfo); // Normalized, case preserved.
260 EXPECT_USTREQ("host.com", uri->host); // Normalized, lower-cased.
261 EXPECT_USTREQ("80", uri->port);
262 EXPECT_USTREQ("/", uri->path);
263 EXPECT(uri->query == nullptr);
264 EXPECT(uri->fragment == nullptr);
265}
266
267TEST_CASE(ParseUri_NormalizeEscapes_UppercaseEscapeInHost) {
268 auto uri = ParseUri("scheme://tEst%1b/");
269 EXPECT(uri);
270 EXPECT_USTREQ("scheme", uri->scheme);
271 EXPECT(uri->userinfo == nullptr);
272 EXPECT_USTREQ("test%1B", uri->host); // Notice that %1B is upper-cased.
273 EXPECT(uri->port == nullptr);
274 EXPECT_USTREQ("/", uri->path);
275 EXPECT(uri->query == nullptr);
276 EXPECT(uri->fragment == nullptr);
277}
278
279TEST_CASE(ParseUri_BrokenEscapeSequence) {
280 auto uri = ParseUri("scheme:/%1g");
281 EXPECT(uri);
282 EXPECT_USTREQ("scheme", uri->scheme);
283 EXPECT(uri->userinfo == nullptr);
284 EXPECT(uri->host == nullptr);
285 EXPECT(uri->port == nullptr);
286 EXPECT_USTREQ("/%1g", uri->path); // Broken sequence is unchanged.
287 EXPECT(uri->query == nullptr);
288 EXPECT(uri->fragment == nullptr);
289}
290
291TEST_CASE(ResolveUri_WithScheme_NoAuthorityNoQuery) {
292 auto target_uri = ResolveUri("rscheme:/ref/path",
293 "bscheme://buser@bhost:11/base/path?baseQuery");
294 EXPECT(target_uri);
295 EXPECT_USTREQ("rscheme:/ref/path", target_uri);
296}
297
298TEST_CASE(ResolveUri_WithScheme_WithAuthorityWithQuery) {
299 auto target_uri = ResolveUri("rscheme://ruser@rhost:22/ref/path?refQuery",
300 "bscheme://buser@bhost:11/base/path?baseQuery");
301 EXPECT(target_uri);
302 EXPECT_USTREQ("rscheme://ruser@rhost:22/ref/path?refQuery", target_uri);
303}
304
305TEST_CASE(ResolveUri_NoScheme_WithAuthority) {
306 auto target_uri = ResolveUri("//ruser@rhost:22/ref/path",
307 "bscheme://buser@bhost:11/base/path?baseQuery");
308 EXPECT(target_uri);
309 EXPECT_USTREQ("bscheme://ruser@rhost:22/ref/path", target_uri);
310}
311
312TEST_CASE(ResolveUri_NoSchemeNoAuthority_AbsolutePath) {
313 auto target_uri =
314 ResolveUri("/ref/path", "bscheme://buser@bhost:11/base/path?baseQuery");
315 EXPECT(target_uri);
316 EXPECT_USTREQ("bscheme://buser@bhost:11/ref/path", target_uri);
317}
318
319TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePath) {
320 auto target_uri =
321 ResolveUri("ref/path", "bscheme://buser@bhost:11/base/path?baseQuery");
322 EXPECT(target_uri);
323 EXPECT_USTREQ("bscheme://buser@bhost:11/base/ref/path", target_uri);
324}
325
326TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePathEmptyBasePath) {
327 auto target_uri = ResolveUri("ref/path", "bscheme://buser@bhost:11");
328 EXPECT(target_uri);
329 EXPECT_USTREQ("bscheme://buser@bhost:11/ref/path", target_uri);
330}
331
332TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePathWeirdBasePath) {
333 auto target_uri = ResolveUri("ref/path", "bscheme:base");
334 EXPECT(target_uri);
335 EXPECT_USTREQ("bscheme:ref/path", target_uri);
336}
337
338TEST_CASE(ResolveUri_NoSchemeNoAuthority_EmptyPath) {
339 auto target_uri =
340 ResolveUri("", "bscheme://buser@bhost:11/base/path?baseQuery#bfragment");
341 EXPECT(target_uri);
342 // Note that we drop the base fragment from the resolved uri->
343 EXPECT_USTREQ("bscheme://buser@bhost:11/base/path?baseQuery", target_uri);
344}
345
346TEST_CASE(ResolveUri_NoSchemeNoAuthority_EmptyPathWithQuery) {
347 auto target_uri = ResolveUri(
348 "?refQuery", "bscheme://buser@bhost:11/base/path?baseQuery#bfragment");
349 EXPECT(target_uri);
350 EXPECT_USTREQ("bscheme://buser@bhost:11/base/path?refQuery", target_uri);
351}
352
353TEST_CASE(ResolveUri_NoSchemeNoAuthority_EmptyPathWithFragment) {
354 auto target_uri = ResolveUri(
355 "#rfragment", "bscheme://buser@bhost:11/base/path?baseQuery#bfragment");
356 EXPECT(target_uri);
357 EXPECT_USTREQ("bscheme://buser@bhost:11/base/path?baseQuery#rfragment",
358 target_uri);
359}
360
361TEST_CASE(ResolveUri_RemoveDots_RemoveOneDotSegment) {
362 auto target_uri = ResolveUri("./refpath", "scheme://auth/a/b/c/d");
363 EXPECT(target_uri);
364 EXPECT_USTREQ("scheme://auth/a/b/c/refpath", target_uri);
365}
366
367TEST_CASE(ResolveUri_RemoveDots_RemoveTwoDotSegments) {
368 auto target_uri = ResolveUri("././refpath", "scheme://auth/a/b/c/d");
369 EXPECT(target_uri);
370 EXPECT_USTREQ("scheme://auth/a/b/c/refpath", target_uri);
371}
372
373TEST_CASE(ResolveUri_RemoveDots_RemoveOneDotDotSegment) {
374 auto target_uri = ResolveUri("../refpath", "scheme://auth/a/b/c/d");
375 EXPECT(target_uri);
376 EXPECT_USTREQ("scheme://auth/a/b/refpath", target_uri);
377}
378
379TEST_CASE(ResolveUri_RemoveDots_RemoveTwoDotDotSegments) {
380 auto target_uri = ResolveUri("../../refpath", "scheme://auth/a/b/c/d");
381 EXPECT(target_uri);
382 EXPECT_USTREQ("scheme://auth/a/refpath", target_uri);
383}
384
385TEST_CASE(ResolveUri_RemoveDots_RemoveTooManyDotDotSegments) {
386 auto target_uri =
387 ResolveUri("../../../../../../../../../refpath", "scheme://auth/a/b/c/d");
388 EXPECT(target_uri);
389 EXPECT_USTREQ("scheme://auth/refpath", target_uri);
390}
391
392TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsNothingLeft1) {
393 auto target_uri = ResolveUri("../../../../..", "scheme://auth/a/b/c/d");
394 EXPECT(target_uri);
395 EXPECT_USTREQ("scheme://auth/", target_uri);
396}
397
398TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsNothingLeft2) {
399 auto target_uri = ResolveUri(".", "scheme://auth/");
400 EXPECT(target_uri);
401 EXPECT_USTREQ("scheme://auth/", target_uri);
402}
403
404TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsInitialPrefix) {
405 auto target_uri = ResolveUri("../../../../refpath", "scheme://auth");
406 EXPECT(target_uri);
407 EXPECT_USTREQ("scheme://auth/refpath", target_uri);
408}
409
410TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsMixed) {
411 auto target_uri = ResolveUri("../../1/./2/../3/4/../5/././6/../7",
412 "scheme://auth/a/b/c/d/e");
413 EXPECT(target_uri);
414 EXPECT_USTREQ("scheme://auth/a/b/1/3/5/7", target_uri);
415}
416
417TEST_CASE(ResolveUri_NormalizeEscapes_PathQueryFragment) {
418 auto target_uri = ResolveUri(
419 "#A Fr%61gment", "scheme:/This%09Is A P%61th?This%09Is A Qu%65ry");
420 EXPECT(target_uri);
422 "scheme:/This%09Is%20A%20Path?This%09Is%20A%20Query#A%20Fragment",
423 target_uri);
424}
425
426TEST_CASE(ResolveUri_NormalizeEscapes_UppercaseHexPreferred) {
427 auto target_uri = ResolveUri("", "scheme:/%1b%1B");
428 EXPECT(target_uri);
429 EXPECT_USTREQ("scheme:/%1B%1B", target_uri);
430}
431
432TEST_CASE(ResolveUri_NormalizeEscapes_Authority) {
433 auto target_uri = ResolveUri("", "scheme://UsEr N%61%4de@h%4FsT.c%6fm:80/");
434 EXPECT(target_uri);
435 // userinfo is normalized and case is preserved. host is normalized
436 // and lower-cased.
437 EXPECT_USTREQ("scheme://UsEr%20NaMe@host.com:80/", target_uri);
438}
439
440TEST_CASE(ResolveUri_NormalizeEscapes_BrokenEscapeSequence) {
441 auto target_uri = ResolveUri("", "scheme:/%1g");
442 EXPECT(target_uri);
443 // We don't change broken escape sequences.
444 EXPECT_USTREQ("scheme:/%1g", target_uri);
445}
446
447TEST_CASE(ResolveUri_DataUri) {
448 const char* data_uri =
449 "data:application/"
450 "dart;charset=utf-8,%20%20%20%20%20%20%20%20import%20%22dart:isolate%22;%"
451 "0A%0A%20%20%20%20%20%20%20%20import%20%22package:stream_channel/"
452 "stream_channel.dart%22;%0A%0A%20%20%20%20%20%20%20%20import%20%"
453 "22package:test/src/runner/plugin/"
454 "remote_platform_helpers.dart%22;%0A%20%20%20%20%20%20%20%20import%20%"
455 "22package:test/src/runner/vm/"
456 "catch_isolate_errors.dart%22;%0A%0A%20%20%20%20%20%20%20%20import%20%"
457 "22file:///home/sra/xxxx/dev_compiler/test/"
458 "all_tests.dart%22%20as%20test;%0A%0A%20%20%20%20%20%20%20%20void%20main("
459 "_,%20SendPort%20message)%20%7B%0A%20%20%20%20%20%20%20%20%20%20var%"
460 "20channel%20=%20serializeSuite(()%20%7B%0A%20%20%20%20%20%20%20%20%20%"
461 "20%20%20catchIsolateErrors();%0A%20%20%20%20%20%20%20%20%20%20%20%"
462 "20return%20test.main;%0A%20%20%20%20%20%20%20%20%20%20%7D);%0A%20%20%20%"
463 "20%20%20%20%20%20%20new%20IsolateChannel.connectSend(message).pipe("
464 "channel);%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20";
465
466 auto target_uri = ResolveUri(
467 data_uri, "bscheme://buser@bhost:11/base/path?baseQuery#bfragment");
468 EXPECT(target_uri);
469 EXPECT_USTREQ(data_uri, target_uri);
470}
471
472// dart:core Uri allows for the base url to be relative (no scheme, no
473// authority, relative path) but this behavior is not in RFC 3986. We
474// do not implement this.
475TEST_CASE(ResolveUri_RelativeBase_NotImplemented) {
476 EXPECT(!ResolveUri("../r1", "b1/b2").get());
477
478 EXPECT(!ResolveUri("..", "b1/b2").get());
479
480 EXPECT(!ResolveUri("../..", "b1/b2").get());
481
482 EXPECT(!ResolveUri("../../..", "b1/b2").get());
483
484 EXPECT(!ResolveUri("../../../r1", "b1/b2").get());
485
486 EXPECT(!ResolveUri("../r1", "../../b1/b2/b3").get());
487
488 EXPECT(!ResolveUri("../../../r1", "../../b1/b2/b3").get());
489}
490
491CStringUniquePtr TestResolve(const char* base_uri, const char* uri) {
492 auto target_uri = ResolveUri(uri, base_uri);
493 EXPECT(target_uri);
494 return target_uri;
495}
496
497// This test is ported from sdk/tests/corelib/uri_test.dart (testUriPerRFCs).
498TEST_CASE(ResolveUri_TestUriPerRFCs) {
499 const char* base = "http://a/b/c/d;p?q";
500
501 // From RFC 3986
502 EXPECT_USTREQ("g:h", TestResolve(base, "g:h"));
503 EXPECT_USTREQ("http://a/b/c/g", TestResolve(base, "g"));
504 EXPECT_USTREQ("http://a/b/c/g", TestResolve(base, "./g"));
505 EXPECT_USTREQ("http://a/b/c/g/", TestResolve(base, "g/"));
506 EXPECT_USTREQ("http://a/g", TestResolve(base, "/g"));
507 EXPECT_USTREQ("http://g", TestResolve(base, "//g"));
508 EXPECT_USTREQ("http://a/b/c/d;p?y", TestResolve(base, "?y"));
509 EXPECT_USTREQ("http://a/b/c/g?y", TestResolve(base, "g?y"));
510 EXPECT_USTREQ("http://a/b/c/d;p?q#s", TestResolve(base, "#s"));
511 EXPECT_USTREQ("http://a/b/c/g#s", TestResolve(base, "g#s"));
512 EXPECT_USTREQ("http://a/b/c/g?y#s", TestResolve(base, "g?y#s"));
513 EXPECT_USTREQ("http://a/b/c/;x", TestResolve(base, ";x"));
514 EXPECT_USTREQ("http://a/b/c/g;x", TestResolve(base, "g;x"));
515 EXPECT_USTREQ("http://a/b/c/g;x?y#s", TestResolve(base, "g;x?y#s"));
516 EXPECT_USTREQ("http://a/b/c/d;p?q", TestResolve(base, ""));
517 EXPECT_USTREQ("http://a/b/c/", TestResolve(base, "."));
518 EXPECT_USTREQ("http://a/b/c/", TestResolve(base, "./"));
519 EXPECT_USTREQ("http://a/b/", TestResolve(base, ".."));
520 EXPECT_USTREQ("http://a/b/", TestResolve(base, "../"));
521 EXPECT_USTREQ("http://a/b/g", TestResolve(base, "../g"));
522 EXPECT_USTREQ("http://a/", TestResolve(base, "../.."));
523 EXPECT_USTREQ("http://a/", TestResolve(base, "../../"));
524 EXPECT_USTREQ("http://a/g", TestResolve(base, "../../g"));
525 EXPECT_USTREQ("http://a/g", TestResolve(base, "../../../g"));
526 EXPECT_USTREQ("http://a/g", TestResolve(base, "../../../../g"));
527 EXPECT_USTREQ("http://a/g", TestResolve(base, "/./g"));
528 EXPECT_USTREQ("http://a/g", TestResolve(base, "/../g"));
529 EXPECT_USTREQ("http://a/b/c/g.", TestResolve(base, "g."));
530 EXPECT_USTREQ("http://a/b/c/.g", TestResolve(base, ".g"));
531 EXPECT_USTREQ("http://a/b/c/g..", TestResolve(base, "g.."));
532 EXPECT_USTREQ("http://a/b/c/..g", TestResolve(base, "..g"));
533 EXPECT_USTREQ("http://a/b/g", TestResolve(base, "./../g"));
534 EXPECT_USTREQ("http://a/b/c/g/", TestResolve(base, "./g/."));
535 EXPECT_USTREQ("http://a/b/c/g/h", TestResolve(base, "g/./h"));
536 EXPECT_USTREQ("http://a/b/c/h", TestResolve(base, "g/../h"));
537 EXPECT_USTREQ("http://a/b/c/g;x=1/y", TestResolve(base, "g;x=1/./y"));
538 EXPECT_USTREQ("http://a/b/c/y", TestResolve(base, "g;x=1/../y"));
539 EXPECT_USTREQ("http://a/b/c/g?y/./x", TestResolve(base, "g?y/./x"));
540 EXPECT_USTREQ("http://a/b/c/g?y/../x", TestResolve(base, "g?y/../x"));
541 EXPECT_USTREQ("http://a/b/c/g#s/./x", TestResolve(base, "g#s/./x"));
542 EXPECT_USTREQ("http://a/b/c/g#s/../x", TestResolve(base, "g#s/../x"));
543 EXPECT_USTREQ("http:g", TestResolve(base, "http:g"));
544
545 // Additional tests (not from RFC 3986).
546 EXPECT_USTREQ("http://a/b/g;p/h;s", TestResolve(base, "../g;p/h;s"));
547
548 base = "s:a/b";
549 EXPECT_USTREQ("s:/c", TestResolve(base, "../c"));
550}
551
552// This test is ported from sdk/tests/corelib/uri_test.dart (testResolvePath).
553TEST_CASE(ResolveUri_MoreDotSegmentTests) {
554 const char* base = "/";
555 EXPECT_USTREQ("/a/g", TestResolve(base, "/a/b/c/./../../g"));
556 EXPECT_USTREQ("/a/g", TestResolve(base, "/a/b/c/./../../g"));
557 EXPECT_USTREQ("/mid/6", TestResolve(base, "mid/content=5/../6"));
558 EXPECT_USTREQ("/a/b/e", TestResolve(base, "a/b/c/d/../../e"));
559 EXPECT_USTREQ("/a/b/e", TestResolve(base, "../a/b/c/d/../../e"));
560 EXPECT_USTREQ("/a/b/e", TestResolve(base, "./a/b/c/d/../../e"));
561 EXPECT_USTREQ("/a/b/e", TestResolve(base, "../a/b/./c/d/../../e"));
562 EXPECT_USTREQ("/a/b/e", TestResolve(base, "./a/b/./c/d/../../e"));
563 EXPECT_USTREQ("/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/."));
564 EXPECT_USTREQ("/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/./."));
565 EXPECT_USTREQ("/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/././."));
566
567#define LH "http://localhost"
568 base = LH;
569 EXPECT_USTREQ(LH "/a/g", TestResolve(base, "/a/b/c/./../../g"));
570 EXPECT_USTREQ(LH "/a/g", TestResolve(base, "/a/b/c/./../../g"));
571 EXPECT_USTREQ(LH "/mid/6", TestResolve(base, "mid/content=5/../6"));
572 EXPECT_USTREQ(LH "/a/b/e", TestResolve(base, "a/b/c/d/../../e"));
573 EXPECT_USTREQ(LH "/a/b/e", TestResolve(base, "../a/b/c/d/../../e"));
574 EXPECT_USTREQ(LH "/a/b/e", TestResolve(base, "./a/b/c/d/../../e"));
575 EXPECT_USTREQ(LH "/a/b/e", TestResolve(base, "../a/b/./c/d/../../e"));
576 EXPECT_USTREQ(LH "/a/b/e", TestResolve(base, "./a/b/./c/d/../../e"));
577 EXPECT_USTREQ(LH "/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/."));
578 EXPECT_USTREQ(LH "/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/./."));
579 EXPECT_USTREQ(LH "/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/././."));
580#undef LH
581}
582
583TEST_CASE(ResolveUri_WindowsPaths_Forwardslash_NoScheme) {
585 "c:/Users/USERNA~1/AppData/Local/Temp/a/b.dll",
586 TestResolve("C:/Users/USERNA~1/AppData/Local/Temp/a/out.dill", "b.dll"));
587}
588
589// > Here are some examples which may be accepted by some applications on
590// > Windows systems
591// https://en.wikipedia.org/wiki/File_URI_scheme
592// "file:///C:/"
593TEST_CASE(ResolveUri_WindowsPaths_Forwardslash_FileScheme) {
595 "file:///"
596 "C:/Users/USERNA~1/AppData/Local/Temp/a/b.dll",
597 TestResolve("file:///C:/Users/USERNA~1/AppData/Local/Temp/a/out.dill",
598 "b.dll"));
599}
600
601TEST_CASE(ResolveUri_WindowsPaths_Backslash) {
603 "file:///b.dll",
605 "file:///C:\\Users\\USERNA~1\\AppData\\Local\\Temp\\a\\out.dill",
606 "b.dll"));
607}
608
609} // namespace dart
#define EXPECT(type, expectedAlignment, expectedSize)
Definition: dart_vm.cc:33
CStringUniquePtr TestResolve(const char *base_uri, const char *uri)
Definition: uri_test.cc:491
std::unique_ptr< ParsedUri > ParseUri(const char *uri)
Definition: uri.cc:215
CStringUniquePtr ResolveUri(const char *ref_uri, const char *base_uri)
Definition: uri.cc:432
TEST_CASE(DirectoryCurrent)
const myers::Point & get(const myers::Segment &)
#define EXPECT_USTREQ(expected, actual)
Definition: uri_test.cc:12