Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1397)

Side by Side Diff: runtime/vm/uri_test.cc

Issue 2011543002: Canonicalize uris in C++ instead of Dart for the standalone embedder. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
23 TEST_CASE(ParseUri_WithScheme_WithQuery) {
24 ParsedUri uri;
25 EXPECT(ParseUri("foo://example.com:8042/over/there?name=ferret", &uri));
26 EXPECT_STREQ("foo", uri.scheme);
27 EXPECT(uri.userinfo == NULL);
28 EXPECT_STREQ("example.com", uri.host);
29 EXPECT_STREQ("8042", uri.port);
30 EXPECT_STREQ("/over/there", uri.path);
31 EXPECT_STREQ("name=ferret", uri.query);
32 EXPECT(uri.fragment == NULL);
33 }
34
35
36 TEST_CASE(ParseUri_WithScheme_WithFragment) {
37 ParsedUri uri;
38 EXPECT(ParseUri("foo://example.com:8042/over/there#fragment", &uri));
39 EXPECT_STREQ("foo", uri.scheme);
40 EXPECT(uri.userinfo == NULL);
41 EXPECT_STREQ("example.com", uri.host);
42 EXPECT_STREQ("8042", uri.port);
43 EXPECT_STREQ("/over/there", uri.path);
44 EXPECT(uri.query == NULL);
45 EXPECT_STREQ("fragment", uri.fragment);
46 }
47
48
49 TEST_CASE(ParseUri_WithScheme_WithQueryWithFragment) {
50 ParsedUri uri;
51 EXPECT(ParseUri("foo://example.com:8042/over/there?name=ferret#fragment",
52 &uri));
53 EXPECT_STREQ("foo", uri.scheme);
54 EXPECT(uri.userinfo == NULL);
55 EXPECT_STREQ("example.com", uri.host);
56 EXPECT_STREQ("8042", uri.port);
57 EXPECT_STREQ("/over/there", uri.path);
58 EXPECT_STREQ("name=ferret", uri.query);
59 EXPECT_STREQ("fragment", uri.fragment);
60 }
61
62
63 TEST_CASE(ParseUri_WithScheme_WithUser) {
64 ParsedUri uri;
65 EXPECT(ParseUri("foo://user@example.com:8042/over/there", &uri));
66 EXPECT_STREQ("foo", uri.scheme);
67 EXPECT_STREQ("user", uri.userinfo);
68 EXPECT_STREQ("example.com", uri.host);
69 EXPECT_STREQ("8042", uri.port);
70 EXPECT_STREQ("/over/there", uri.path);
71 EXPECT(uri.query == NULL);
72 EXPECT(uri.fragment == NULL);
73 }
74
75
76 TEST_CASE(ParseUri_WithScheme_ShortPath) {
77 ParsedUri uri;
78 EXPECT(ParseUri("foo://example.com:8042/", &uri));
79 EXPECT_STREQ("foo", uri.scheme);
80 EXPECT(uri.userinfo == NULL);
81 EXPECT_STREQ("example.com", uri.host);
82 EXPECT_STREQ("8042", uri.port);
83 EXPECT_STREQ("/", uri.path);
84 EXPECT(uri.query == NULL);
85 EXPECT(uri.fragment == NULL);
86 }
87
88
89 TEST_CASE(ParseUri_WithScheme_EmptyPath) {
90 ParsedUri uri;
91 EXPECT(ParseUri("foo://example.com:8042", &uri));
92 EXPECT_STREQ("foo", uri.scheme);
93 EXPECT(uri.userinfo == NULL);
94 EXPECT_STREQ("example.com", uri.host);
95 EXPECT_STREQ("8042", uri.port);
96 EXPECT_STREQ("", uri.path);
97 EXPECT(uri.query == NULL);
98 EXPECT(uri.fragment == NULL);
99 }
100
101
102 TEST_CASE(ParseUri_WithScheme_Rootless1) {
103 ParsedUri uri;
104 EXPECT(ParseUri("foo:here", &uri));
105 EXPECT_STREQ("foo", uri.scheme);
106 EXPECT(uri.userinfo == NULL);
107 EXPECT(uri.host == NULL);
108 EXPECT(uri.port == NULL);
109 EXPECT_STREQ("here", uri.path);
110 EXPECT(uri.query == NULL);
111 EXPECT(uri.fragment == NULL);
112 }
113
114
115 TEST_CASE(ParseUri_WithScheme_Rootless2) {
116 ParsedUri uri;
117 EXPECT(ParseUri("foo:or/here", &uri));
118 EXPECT_STREQ("foo", uri.scheme);
119 EXPECT(uri.userinfo == NULL);
120 EXPECT(uri.host == NULL);
121 EXPECT(uri.port == NULL);
122 EXPECT_STREQ("or/here", uri.path);
123 EXPECT(uri.query == NULL);
124 EXPECT(uri.fragment == NULL);
125 }
126
127
128 TEST_CASE(ParseUri_NoScheme_AbsPath_WithAuthority) {
129 ParsedUri uri;
130 EXPECT(ParseUri("//example.com:8042/over/there", &uri));
131 EXPECT(uri.scheme == NULL);
132 EXPECT(uri.userinfo == NULL);
133 EXPECT_STREQ("example.com", uri.host);
134 EXPECT_STREQ("8042", uri.port);
135 EXPECT_STREQ("/over/there", uri.path);
136 EXPECT(uri.query == NULL);
137 EXPECT(uri.fragment == NULL);
138 }
139
140
141 TEST_CASE(ParseUri_NoScheme_AbsPath_NoAuthority) {
142 ParsedUri uri;
143 EXPECT(ParseUri("/over/there", &uri));
144 EXPECT(uri.scheme == NULL);
145 EXPECT(uri.userinfo == NULL);
146 EXPECT(uri.host == NULL);
147 EXPECT(uri.port == NULL);
148 EXPECT_STREQ("/over/there", uri.path);
149 EXPECT(uri.query == NULL);
150 EXPECT(uri.fragment == NULL);
151 }
152
153
154 // Colons are permitted in path segments, in many cases.
155 TEST_CASE(ParseUri_NoScheme_AbsPath_StrayColon) {
156 ParsedUri uri;
157 EXPECT(ParseUri("/ov:er/there", &uri));
158 EXPECT(uri.scheme == NULL);
159 EXPECT(uri.userinfo == NULL);
160 EXPECT(uri.host == NULL);
161 EXPECT(uri.port == NULL);
162 EXPECT_STREQ("/ov:er/there", uri.path);
163 EXPECT(uri.query == NULL);
164 }
165
166
167 TEST_CASE(ParseUri_NoScheme_Rootless1) {
168 ParsedUri uri;
169 EXPECT(ParseUri("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("here", uri.path);
175 EXPECT(uri.query == NULL);
176 EXPECT(uri.fragment == NULL);
177 }
178
179
180 TEST_CASE(ParseUri_NoScheme_Rootless2) {
181 ParsedUri uri;
182 EXPECT(ParseUri("or/here", &uri));
183 EXPECT(uri.scheme == NULL);
184 EXPECT(uri.userinfo == NULL);
185 EXPECT(uri.host == NULL);
186 EXPECT(uri.port == NULL);
187 EXPECT_STREQ("or/here", uri.path);
188 EXPECT(uri.query == NULL);
189 EXPECT(uri.fragment == NULL);
190 }
191
192
193 TEST_CASE(ParseUri_NoScheme_Empty) {
194 ParsedUri uri;
195 EXPECT(ParseUri("", &uri));
196 EXPECT(uri.scheme == NULL);
197 EXPECT(uri.userinfo == NULL);
198 EXPECT(uri.host == NULL);
199 EXPECT(uri.port == NULL);
200 EXPECT_STREQ("", uri.path);
201 EXPECT(uri.query == NULL);
202 EXPECT(uri.fragment == NULL);
203 }
204
205
206 TEST_CASE(ParseUri_NoScheme_QueryOnly) {
207 ParsedUri uri;
208 EXPECT(ParseUri("?name=ferret", &uri));
209 EXPECT(uri.scheme == NULL);
210 EXPECT(uri.userinfo == NULL);
211 EXPECT(uri.host == NULL);
212 EXPECT(uri.port == NULL);
213 EXPECT_STREQ("", uri.path);
214 EXPECT_STREQ("name=ferret", uri.query);
215 EXPECT(uri.fragment == NULL);
216 }
217
218
219 TEST_CASE(ParseUri_NoScheme_FragmentOnly) {
220 ParsedUri uri;
221 EXPECT(ParseUri("#fragment", &uri));
222 EXPECT(uri.scheme == NULL);
223 EXPECT(uri.userinfo == NULL);
224 EXPECT(uri.host == NULL);
225 EXPECT(uri.port == NULL);
226 EXPECT_STREQ("", uri.path);
227 EXPECT(uri.query == NULL);
228 EXPECT_STREQ("fragment", uri.fragment);
229 }
230
231
232 TEST_CASE(ParseUri_DoubleSlash1) {
233 ParsedUri uri;
234 EXPECT(!ParseUri("foo://example.com:8042/over//there?name=ferret", &uri));
235 EXPECT(uri.scheme == NULL);
236 EXPECT(uri.userinfo == NULL);
237 EXPECT(uri.host == NULL);
238 EXPECT(uri.port == NULL);
239 EXPECT(uri.path == NULL);
240 EXPECT(uri.query == NULL);
241 EXPECT(uri.fragment == NULL);
242 }
243
244
245 TEST_CASE(ParseUri_DoubleSlash2) {
246 ParsedUri uri;
247 EXPECT(!ParseUri("or//here", &uri));
248 EXPECT(uri.scheme == NULL);
249 EXPECT(uri.userinfo == NULL);
250 EXPECT(uri.host == NULL);
251 EXPECT(uri.port == NULL);
252 EXPECT(uri.path == NULL);
253 EXPECT(uri.query == NULL);
254 EXPECT(uri.fragment == NULL);
255 }
256
257
258 TEST_CASE(ParseUri_LowerCaseScheme) {
259 ParsedUri uri;
260 EXPECT(ParseUri("ScHeMe:path", &uri));
261 EXPECT_STREQ("scheme", uri.scheme);
262 EXPECT(uri.userinfo == NULL);
263 EXPECT(uri.host == NULL);
264 EXPECT(uri.port == NULL);
265 EXPECT_STREQ("path", uri.path);
266 EXPECT(uri.query == NULL);
267 EXPECT(uri.fragment == NULL);
268 }
269
270
271 TEST_CASE(ParseUri_NormalizeEscapes_PathQueryFragment) {
272 ParsedUri uri;
273 EXPECT(ParseUri(
274 "scheme:/This%09Is A P%61th?This%09Is A Qu%65ry#A Fr%61gment", &uri));
275 EXPECT_STREQ("scheme", uri.scheme);
276 EXPECT(uri.userinfo == NULL);
277 EXPECT(uri.host == NULL);
278 EXPECT(uri.port == NULL);
279 EXPECT_STREQ("/This%09Is%20A%20Path", uri.path);
280 EXPECT_STREQ("This%09Is%20A%20Query", uri.query);
281 EXPECT_STREQ("A%20Fragment", uri.fragment);
282 }
283
284
285 TEST_CASE(ParseUri_NormalizeEscapes_UppercaseEscapesPreferred) {
286 ParsedUri uri;
287 EXPECT(ParseUri(
288 "scheme:/%1b%1B", &uri));
289 EXPECT_STREQ("scheme", uri.scheme);
290 EXPECT(uri.userinfo == NULL);
291 EXPECT(uri.host == NULL);
292 EXPECT(uri.port == NULL);
293 EXPECT_STREQ("/%1B%1B", uri.path);
294 EXPECT(uri.query == NULL);
295 EXPECT(uri.fragment == NULL);
296 }
297
298
299 TEST_CASE(ParseUri_NormalizeEscapes_Authority) {
300 ParsedUri uri;
301 EXPECT(ParseUri(
302 "scheme://UsEr N%61%4de@h%4FsT.c%6fm:80/", &uri));
303 EXPECT_STREQ("scheme", uri.scheme);
304 EXPECT_STREQ("UsEr%20NaMe", uri.userinfo); // Normalized, case preserved.
305 EXPECT_STREQ("host.com", uri.host); // Normalized, lower-cased.
306 EXPECT_STREQ("80", uri.port);
307 EXPECT_STREQ("/", uri.path);
308 EXPECT(uri.query == NULL);
309 EXPECT(uri.fragment == NULL);
310 }
311
312
313 TEST_CASE(ParseUri_BrokenEscapeSequence) {
314 ParsedUri uri;
315 EXPECT(ParseUri(
316 "scheme:/%1g", &uri));
317 EXPECT_STREQ("scheme", uri.scheme);
318 EXPECT(uri.userinfo == NULL);
319 EXPECT(uri.host == NULL);
320 EXPECT(uri.port == NULL);
321 EXPECT_STREQ("/%1g", uri.path); // Broken sequence is unchanged.
322 EXPECT(uri.query == NULL);
323 EXPECT(uri.fragment == NULL);
324 }
325
326
327 TEST_CASE(ResolveUri_WithScheme_NoAuthorityNoQuery) {
328 const char* target_uri;
329 EXPECT(ResolveUri("rscheme:/ref/path",
330 "bscheme://buser@bhost:11/base/path?baseQuery",
331 &target_uri));
332 EXPECT_STREQ("rscheme:/ref/path", target_uri);
333 }
334
335
336 TEST_CASE(ResolveUri_WithScheme_WithAuthorityWithQuery) {
337 const char* target_uri;
338 EXPECT(ResolveUri("rscheme://ruser@rhost:22/ref/path?refQuery",
339 "bscheme://buser@bhost:11/base/path?baseQuery",
340 &target_uri));
341 EXPECT_STREQ("rscheme://ruser@rhost:22/ref/path?refQuery", target_uri);
342 }
343
344
345 TEST_CASE(ResolveUri_NoScheme_WithAuthority) {
346 const char* target_uri;
347 EXPECT(ResolveUri("//ruser@rhost:22/ref/path",
348 "bscheme://buser@bhost:11/base/path?baseQuery",
349 &target_uri));
350 EXPECT_STREQ("bscheme://ruser@rhost:22/ref/path", target_uri);
351 }
352
353
354 TEST_CASE(ResolveUri_NoSchemeNoAuthority_AbsolutePath) {
355 const char* target_uri;
356 EXPECT(ResolveUri("/ref/path",
357 "bscheme://buser@bhost:11/base/path?baseQuery",
358 &target_uri));
359 EXPECT_STREQ("bscheme://buser@bhost:11/ref/path", target_uri);
360 }
361
362
363 TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePath) {
364 const char* target_uri;
365 EXPECT(ResolveUri("ref/path",
366 "bscheme://buser@bhost:11/base/path?baseQuery",
367 &target_uri));
368 EXPECT_STREQ("bscheme://buser@bhost:11/base/ref/path", target_uri);
369 }
370
371
372 TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePathEmptyBasePath) {
373 const char* target_uri;
374 EXPECT(ResolveUri("ref/path",
375 "bscheme://buser@bhost:11",
376 &target_uri));
377 EXPECT_STREQ("bscheme://buser@bhost:11/ref/path", target_uri);
378 }
379
380
381 TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePathWeirdBasePath) {
382 const char* target_uri;
383 EXPECT(ResolveUri("ref/path",
384 "bscheme:base",
385 &target_uri));
386 EXPECT_STREQ("bscheme:ref/path", target_uri);
387 }
388
389
390 TEST_CASE(ResolveUri_NoSchemeNoAuthority_EmptyPath) {
391 const char* target_uri;
392 EXPECT(ResolveUri("",
393 "bscheme://buser@bhost:11/base/path?baseQuery#bfragment",
394 &target_uri));
395 // Note that we drop the base fragment from the resolved uri.
396 EXPECT_STREQ("bscheme://buser@bhost:11/base/path?baseQuery", target_uri);
397 }
398
399
400 TEST_CASE(ResolveUri_NoSchemeNoAuthority_EmptyPathWithQuery) {
401 const char* target_uri;
402 EXPECT(ResolveUri("?refQuery",
403 "bscheme://buser@bhost:11/base/path?baseQuery#bfragment",
404 &target_uri));
405 EXPECT_STREQ("bscheme://buser@bhost:11/base/path?refQuery", target_uri);
406 }
407
408
409 TEST_CASE(ResolveUri_NoSchemeNoAuthority_EmptyPathWithFragment) {
410 const char* target_uri;
411 EXPECT(ResolveUri("#rfragment",
412 "bscheme://buser@bhost:11/base/path?baseQuery#bfragment",
413 &target_uri));
414 EXPECT_STREQ("bscheme://buser@bhost:11/base/path?baseQuery#rfragment",
415 target_uri);
416 }
417
418
419 TEST_CASE(ResolveUri_RemoveDots_RemoveOneDotSegment) {
420 const char* target_uri;
421 EXPECT(ResolveUri("./refpath",
422 "scheme://auth/a/b/c/d",
423 &target_uri));
424 EXPECT_STREQ("scheme://auth/a/b/c/refpath", target_uri);
425 }
426
427
428 TEST_CASE(ResolveUri_RemoveDots_RemoveTwoDotSegments) {
429 const char* target_uri;
430 EXPECT(ResolveUri("././refpath",
431 "scheme://auth/a/b/c/d",
432 &target_uri));
433 EXPECT_STREQ("scheme://auth/a/b/c/refpath", target_uri);
434 }
435
436
437 TEST_CASE(ResolveUri_RemoveDots_RemoveOneDotDotSegment) {
438 const char* target_uri;
439 EXPECT(ResolveUri("../refpath",
440 "scheme://auth/a/b/c/d",
441 &target_uri));
442 EXPECT_STREQ("scheme://auth/a/b/refpath", target_uri);
443 }
444
445
446 TEST_CASE(ResolveUri_RemoveDots_RemoveTwoDotDotSegments) {
447 const char* target_uri;
448 EXPECT(ResolveUri("../../refpath",
449 "scheme://auth/a/b/c/d",
450 &target_uri));
451 EXPECT_STREQ("scheme://auth/a/refpath", target_uri);
452 }
453
454
455 TEST_CASE(ResolveUri_RemoveDots_RemoveTooManyDotDotSegments) {
456 const char* target_uri;
457 EXPECT(ResolveUri("../../../../../../../../../refpath",
458 "scheme://auth/a/b/c/d",
459 &target_uri));
460 EXPECT_STREQ("scheme://auth/refpath", target_uri);
461 }
462
463
464 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsNothingLeft1) {
465 const char* target_uri;
466 EXPECT(ResolveUri("../../../../..",
467 "scheme://auth/a/b/c/d",
468 &target_uri));
469 EXPECT_STREQ("scheme://auth/", target_uri);
470 }
471
472
473
474 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsNothingLeft2) {
475 const char* target_uri;
476 EXPECT(ResolveUri(".",
477 "scheme://auth/",
478 &target_uri));
479 EXPECT_STREQ("scheme://auth/", target_uri);
480 }
481
482
483
484 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsInitialPrefix) {
485 const char* target_uri;
486 EXPECT(ResolveUri("../../../../refpath",
487 "scheme://auth",
488 &target_uri));
489 EXPECT_STREQ("scheme://auth/refpath", target_uri);
490 }
491
492
493
494 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsMixed) {
495 const char* target_uri;
496 EXPECT(ResolveUri("../../1/./2/../3/4/../5/././6/../7",
497 "scheme://auth/a/b/c/d/e",
498 &target_uri));
499 EXPECT_STREQ("scheme://auth/a/b/1/3/5/7", target_uri);
500 }
501
502
503 TEST_CASE(ResolveUri_NormalizeEscapes_PathQueryFragment) {
504 const char* target_uri;
505 EXPECT(ResolveUri("#A Fr%61gment",
506 "scheme:/This%09Is A P%61th?This%09Is A Qu%65ry",
507 &target_uri));
508 EXPECT_STREQ(
509 "scheme:/This%09Is%20A%20Path?This%09Is%20A%20Query#A%20Fragment",
510 target_uri);
511 }
512
513
514 TEST_CASE(ResolveUri_NormalizeEscapes_UppercaseHexPreferred) {
515 const char* target_uri;
516 EXPECT(ResolveUri("",
517 "scheme:/%1b%1B",
518 &target_uri));
519 EXPECT_STREQ("scheme:/%1B%1B",
520 target_uri);
521 }
522
523
524 TEST_CASE(ResolveUri_NormalizeEscapes_Authority) {
525 const char* target_uri;
526 EXPECT(ResolveUri("",
527 "scheme://UsEr N%61%4de@h%4FsT.c%6fm:80/",
528 &target_uri));
529 // userinfo is normalized and case is preserved. host is normalized
530 // and lower-cased.
531 EXPECT_STREQ("scheme://UsEr%20NaMe@host.com:80/", target_uri);
532 }
533
534
535 TEST_CASE(ResolveUri_NormalizeEscapes_BrokenEscapeSequence) {
536 const char* target_uri;
537 EXPECT(ResolveUri("",
538 "scheme:/%1g",
539 &target_uri));
540 // We don't change broken escape sequences.
541 EXPECT_STREQ("scheme:/%1g",
542 target_uri);
543 }
ahe 2016/05/25 12:44:52 I can't tell if this is a port of tests/corelib/ur
turnidge 2016/05/27 21:40:06 Well if it wasn't clear, it wasn't a port. I have
544
545 } // namespace dart
OLDNEW
« runtime/vm/uri.cc ('K') | « runtime/vm/uri.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698