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