OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 #include "vm/uri.h" | 5 #include "vm/uri.h" |
6 #include "vm/unit_test.h" | 6 #include "vm/unit_test.h" |
7 | 7 |
8 namespace dart { | 8 namespace dart { |
9 | 9 |
10 TEST_CASE(ParseUri_WithScheme_NoQueryNoUser) { | 10 TEST_CASE(ParseUri_WithScheme_NoQueryNoUser) { |
(...skipping 30 matching lines...) Expand all Loading... |
41 EXPECT_STREQ("example.com", uri.host); | 41 EXPECT_STREQ("example.com", uri.host); |
42 EXPECT_STREQ("8042", uri.port); | 42 EXPECT_STREQ("8042", uri.port); |
43 EXPECT_STREQ("/over/there", uri.path); | 43 EXPECT_STREQ("/over/there", uri.path); |
44 EXPECT(uri.query == NULL); | 44 EXPECT(uri.query == NULL); |
45 EXPECT_STREQ("fragment", uri.fragment); | 45 EXPECT_STREQ("fragment", uri.fragment); |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 TEST_CASE(ParseUri_WithScheme_WithQueryWithFragment) { | 49 TEST_CASE(ParseUri_WithScheme_WithQueryWithFragment) { |
50 ParsedUri uri; | 50 ParsedUri uri; |
51 EXPECT(ParseUri("foo://example.com:8042/over/there?name=ferret#fragment", | 51 EXPECT( |
52 &uri)); | 52 ParseUri("foo://example.com:8042/over/there?name=ferret#fragment", &uri)); |
53 EXPECT_STREQ("foo", uri.scheme); | 53 EXPECT_STREQ("foo", uri.scheme); |
54 EXPECT(uri.userinfo == NULL); | 54 EXPECT(uri.userinfo == NULL); |
55 EXPECT_STREQ("example.com", uri.host); | 55 EXPECT_STREQ("example.com", uri.host); |
56 EXPECT_STREQ("8042", uri.port); | 56 EXPECT_STREQ("8042", uri.port); |
57 EXPECT_STREQ("/over/there", uri.path); | 57 EXPECT_STREQ("/over/there", uri.path); |
58 EXPECT_STREQ("name=ferret", uri.query); | 58 EXPECT_STREQ("name=ferret", uri.query); |
59 EXPECT_STREQ("fragment", uri.fragment); | 59 EXPECT_STREQ("fragment", uri.fragment); |
60 } | 60 } |
61 | 61 |
62 | 62 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 EXPECT(uri.host == NULL); | 237 EXPECT(uri.host == NULL); |
238 EXPECT(uri.port == NULL); | 238 EXPECT(uri.port == NULL); |
239 EXPECT_STREQ("path", uri.path); | 239 EXPECT_STREQ("path", uri.path); |
240 EXPECT(uri.query == NULL); | 240 EXPECT(uri.query == NULL); |
241 EXPECT(uri.fragment == NULL); | 241 EXPECT(uri.fragment == NULL); |
242 } | 242 } |
243 | 243 |
244 | 244 |
245 TEST_CASE(ParseUri_NormalizeEscapes_PathQueryFragment) { | 245 TEST_CASE(ParseUri_NormalizeEscapes_PathQueryFragment) { |
246 ParsedUri uri; | 246 ParsedUri uri; |
247 EXPECT(ParseUri( | 247 EXPECT(ParseUri("scheme:/This%09Is A P%61th?This%09Is A Qu%65ry#A Fr%61gment", |
248 "scheme:/This%09Is A P%61th?This%09Is A Qu%65ry#A Fr%61gment", &uri)); | 248 &uri)); |
249 EXPECT_STREQ("scheme", uri.scheme); | 249 EXPECT_STREQ("scheme", uri.scheme); |
250 EXPECT(uri.userinfo == NULL); | 250 EXPECT(uri.userinfo == NULL); |
251 EXPECT(uri.host == NULL); | 251 EXPECT(uri.host == NULL); |
252 EXPECT(uri.port == NULL); | 252 EXPECT(uri.port == NULL); |
253 EXPECT_STREQ("/This%09Is%20A%20Path", uri.path); | 253 EXPECT_STREQ("/This%09Is%20A%20Path", uri.path); |
254 EXPECT_STREQ("This%09Is%20A%20Query", uri.query); | 254 EXPECT_STREQ("This%09Is%20A%20Query", uri.query); |
255 EXPECT_STREQ("A%20Fragment", uri.fragment); | 255 EXPECT_STREQ("A%20Fragment", uri.fragment); |
256 } | 256 } |
257 | 257 |
258 | 258 |
259 TEST_CASE(ParseUri_NormalizeEscapes_UppercaseEscapesPreferred) { | 259 TEST_CASE(ParseUri_NormalizeEscapes_UppercaseEscapesPreferred) { |
260 ParsedUri uri; | 260 ParsedUri uri; |
261 EXPECT(ParseUri( | 261 EXPECT(ParseUri("scheme:/%1b%1B", &uri)); |
262 "scheme:/%1b%1B", &uri)); | |
263 EXPECT_STREQ("scheme", uri.scheme); | 262 EXPECT_STREQ("scheme", uri.scheme); |
264 EXPECT(uri.userinfo == NULL); | 263 EXPECT(uri.userinfo == NULL); |
265 EXPECT(uri.host == NULL); | 264 EXPECT(uri.host == NULL); |
266 EXPECT(uri.port == NULL); | 265 EXPECT(uri.port == NULL); |
267 EXPECT_STREQ("/%1B%1B", uri.path); | 266 EXPECT_STREQ("/%1B%1B", uri.path); |
268 EXPECT(uri.query == NULL); | 267 EXPECT(uri.query == NULL); |
269 EXPECT(uri.fragment == NULL); | 268 EXPECT(uri.fragment == NULL); |
270 } | 269 } |
271 | 270 |
272 | 271 |
273 TEST_CASE(ParseUri_NormalizeEscapes_Authority) { | 272 TEST_CASE(ParseUri_NormalizeEscapes_Authority) { |
274 ParsedUri uri; | 273 ParsedUri uri; |
275 EXPECT(ParseUri( | 274 EXPECT(ParseUri("scheme://UsEr N%61%4de@h%4FsT.c%6fm:80/", &uri)); |
276 "scheme://UsEr N%61%4de@h%4FsT.c%6fm:80/", &uri)); | |
277 EXPECT_STREQ("scheme", uri.scheme); | 275 EXPECT_STREQ("scheme", uri.scheme); |
278 EXPECT_STREQ("UsEr%20NaMe", uri.userinfo); // Normalized, case preserved. | 276 EXPECT_STREQ("UsEr%20NaMe", uri.userinfo); // Normalized, case preserved. |
279 EXPECT_STREQ("host.com", uri.host); // Normalized, lower-cased. | 277 EXPECT_STREQ("host.com", uri.host); // Normalized, lower-cased. |
280 EXPECT_STREQ("80", uri.port); | 278 EXPECT_STREQ("80", uri.port); |
281 EXPECT_STREQ("/", uri.path); | 279 EXPECT_STREQ("/", uri.path); |
282 EXPECT(uri.query == NULL); | 280 EXPECT(uri.query == NULL); |
283 EXPECT(uri.fragment == NULL); | 281 EXPECT(uri.fragment == NULL); |
284 } | 282 } |
285 | 283 |
286 | 284 |
287 TEST_CASE(ParseUri_NormalizeEscapes_UppercaseEscapeInHost) { | 285 TEST_CASE(ParseUri_NormalizeEscapes_UppercaseEscapeInHost) { |
288 ParsedUri uri; | 286 ParsedUri uri; |
289 EXPECT(ParseUri("scheme://tEst%1b/", &uri)); | 287 EXPECT(ParseUri("scheme://tEst%1b/", &uri)); |
290 EXPECT_STREQ("scheme", uri.scheme); | 288 EXPECT_STREQ("scheme", uri.scheme); |
291 EXPECT(uri.userinfo == NULL); | 289 EXPECT(uri.userinfo == NULL); |
292 EXPECT_STREQ("test%1B", uri.host); // Notice that %1B is upper-cased. | 290 EXPECT_STREQ("test%1B", uri.host); // Notice that %1B is upper-cased. |
293 EXPECT(uri.port == NULL); | 291 EXPECT(uri.port == NULL); |
294 EXPECT_STREQ("/", uri.path); | 292 EXPECT_STREQ("/", uri.path); |
295 EXPECT(uri.query == NULL); | 293 EXPECT(uri.query == NULL); |
296 EXPECT(uri.fragment == NULL); | 294 EXPECT(uri.fragment == NULL); |
297 } | 295 } |
298 | 296 |
299 | 297 |
300 TEST_CASE(ParseUri_BrokenEscapeSequence) { | 298 TEST_CASE(ParseUri_BrokenEscapeSequence) { |
301 ParsedUri uri; | 299 ParsedUri uri; |
302 EXPECT(ParseUri( | 300 EXPECT(ParseUri("scheme:/%1g", &uri)); |
303 "scheme:/%1g", &uri)); | |
304 EXPECT_STREQ("scheme", uri.scheme); | 301 EXPECT_STREQ("scheme", uri.scheme); |
305 EXPECT(uri.userinfo == NULL); | 302 EXPECT(uri.userinfo == NULL); |
306 EXPECT(uri.host == NULL); | 303 EXPECT(uri.host == NULL); |
307 EXPECT(uri.port == NULL); | 304 EXPECT(uri.port == NULL); |
308 EXPECT_STREQ("/%1g", uri.path); // Broken sequence is unchanged. | 305 EXPECT_STREQ("/%1g", uri.path); // Broken sequence is unchanged. |
309 EXPECT(uri.query == NULL); | 306 EXPECT(uri.query == NULL); |
310 EXPECT(uri.fragment == NULL); | 307 EXPECT(uri.fragment == NULL); |
311 } | 308 } |
312 | 309 |
313 | 310 |
(...skipping 19 matching lines...) Expand all Loading... |
333 const char* target_uri; | 330 const char* target_uri; |
334 EXPECT(ResolveUri("//ruser@rhost:22/ref/path", | 331 EXPECT(ResolveUri("//ruser@rhost:22/ref/path", |
335 "bscheme://buser@bhost:11/base/path?baseQuery", | 332 "bscheme://buser@bhost:11/base/path?baseQuery", |
336 &target_uri)); | 333 &target_uri)); |
337 EXPECT_STREQ("bscheme://ruser@rhost:22/ref/path", target_uri); | 334 EXPECT_STREQ("bscheme://ruser@rhost:22/ref/path", target_uri); |
338 } | 335 } |
339 | 336 |
340 | 337 |
341 TEST_CASE(ResolveUri_NoSchemeNoAuthority_AbsolutePath) { | 338 TEST_CASE(ResolveUri_NoSchemeNoAuthority_AbsolutePath) { |
342 const char* target_uri; | 339 const char* target_uri; |
343 EXPECT(ResolveUri("/ref/path", | 340 EXPECT(ResolveUri("/ref/path", "bscheme://buser@bhost:11/base/path?baseQuery", |
344 "bscheme://buser@bhost:11/base/path?baseQuery", | |
345 &target_uri)); | 341 &target_uri)); |
346 EXPECT_STREQ("bscheme://buser@bhost:11/ref/path", target_uri); | 342 EXPECT_STREQ("bscheme://buser@bhost:11/ref/path", target_uri); |
347 } | 343 } |
348 | 344 |
349 | 345 |
350 TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePath) { | 346 TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePath) { |
351 const char* target_uri; | 347 const char* target_uri; |
352 EXPECT(ResolveUri("ref/path", | 348 EXPECT(ResolveUri("ref/path", "bscheme://buser@bhost:11/base/path?baseQuery", |
353 "bscheme://buser@bhost:11/base/path?baseQuery", | |
354 &target_uri)); | 349 &target_uri)); |
355 EXPECT_STREQ("bscheme://buser@bhost:11/base/ref/path", target_uri); | 350 EXPECT_STREQ("bscheme://buser@bhost:11/base/ref/path", target_uri); |
356 } | 351 } |
357 | 352 |
358 | 353 |
359 TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePathEmptyBasePath) { | 354 TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePathEmptyBasePath) { |
360 const char* target_uri; | 355 const char* target_uri; |
361 EXPECT(ResolveUri("ref/path", | 356 EXPECT(ResolveUri("ref/path", "bscheme://buser@bhost:11", &target_uri)); |
362 "bscheme://buser@bhost:11", | |
363 &target_uri)); | |
364 EXPECT_STREQ("bscheme://buser@bhost:11/ref/path", target_uri); | 357 EXPECT_STREQ("bscheme://buser@bhost:11/ref/path", target_uri); |
365 } | 358 } |
366 | 359 |
367 | 360 |
368 TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePathWeirdBasePath) { | 361 TEST_CASE(ResolveUri_NoSchemeNoAuthority_RelativePathWeirdBasePath) { |
369 const char* target_uri; | 362 const char* target_uri; |
370 EXPECT(ResolveUri("ref/path", | 363 EXPECT(ResolveUri("ref/path", "bscheme:base", &target_uri)); |
371 "bscheme:base", | |
372 &target_uri)); | |
373 EXPECT_STREQ("bscheme:ref/path", target_uri); | 364 EXPECT_STREQ("bscheme:ref/path", target_uri); |
374 } | 365 } |
375 | 366 |
376 | 367 |
377 TEST_CASE(ResolveUri_NoSchemeNoAuthority_EmptyPath) { | 368 TEST_CASE(ResolveUri_NoSchemeNoAuthority_EmptyPath) { |
378 const char* target_uri; | 369 const char* target_uri; |
379 EXPECT(ResolveUri("", | 370 EXPECT(ResolveUri("", |
380 "bscheme://buser@bhost:11/base/path?baseQuery#bfragment", | 371 "bscheme://buser@bhost:11/base/path?baseQuery#bfragment", |
381 &target_uri)); | 372 &target_uri)); |
382 // Note that we drop the base fragment from the resolved uri. | 373 // Note that we drop the base fragment from the resolved uri. |
(...skipping 15 matching lines...) Expand all Loading... |
398 EXPECT(ResolveUri("#rfragment", | 389 EXPECT(ResolveUri("#rfragment", |
399 "bscheme://buser@bhost:11/base/path?baseQuery#bfragment", | 390 "bscheme://buser@bhost:11/base/path?baseQuery#bfragment", |
400 &target_uri)); | 391 &target_uri)); |
401 EXPECT_STREQ("bscheme://buser@bhost:11/base/path?baseQuery#rfragment", | 392 EXPECT_STREQ("bscheme://buser@bhost:11/base/path?baseQuery#rfragment", |
402 target_uri); | 393 target_uri); |
403 } | 394 } |
404 | 395 |
405 | 396 |
406 TEST_CASE(ResolveUri_RemoveDots_RemoveOneDotSegment) { | 397 TEST_CASE(ResolveUri_RemoveDots_RemoveOneDotSegment) { |
407 const char* target_uri; | 398 const char* target_uri; |
408 EXPECT(ResolveUri("./refpath", | 399 EXPECT(ResolveUri("./refpath", "scheme://auth/a/b/c/d", &target_uri)); |
409 "scheme://auth/a/b/c/d", | |
410 &target_uri)); | |
411 EXPECT_STREQ("scheme://auth/a/b/c/refpath", target_uri); | 400 EXPECT_STREQ("scheme://auth/a/b/c/refpath", target_uri); |
412 } | 401 } |
413 | 402 |
414 | 403 |
415 TEST_CASE(ResolveUri_RemoveDots_RemoveTwoDotSegments) { | 404 TEST_CASE(ResolveUri_RemoveDots_RemoveTwoDotSegments) { |
416 const char* target_uri; | 405 const char* target_uri; |
417 EXPECT(ResolveUri("././refpath", | 406 EXPECT(ResolveUri("././refpath", "scheme://auth/a/b/c/d", &target_uri)); |
418 "scheme://auth/a/b/c/d", | |
419 &target_uri)); | |
420 EXPECT_STREQ("scheme://auth/a/b/c/refpath", target_uri); | 407 EXPECT_STREQ("scheme://auth/a/b/c/refpath", target_uri); |
421 } | 408 } |
422 | 409 |
423 | 410 |
424 TEST_CASE(ResolveUri_RemoveDots_RemoveOneDotDotSegment) { | 411 TEST_CASE(ResolveUri_RemoveDots_RemoveOneDotDotSegment) { |
425 const char* target_uri; | 412 const char* target_uri; |
426 EXPECT(ResolveUri("../refpath", | 413 EXPECT(ResolveUri("../refpath", "scheme://auth/a/b/c/d", &target_uri)); |
427 "scheme://auth/a/b/c/d", | |
428 &target_uri)); | |
429 EXPECT_STREQ("scheme://auth/a/b/refpath", target_uri); | 414 EXPECT_STREQ("scheme://auth/a/b/refpath", target_uri); |
430 } | 415 } |
431 | 416 |
432 | 417 |
433 TEST_CASE(ResolveUri_RemoveDots_RemoveTwoDotDotSegments) { | 418 TEST_CASE(ResolveUri_RemoveDots_RemoveTwoDotDotSegments) { |
434 const char* target_uri; | 419 const char* target_uri; |
435 EXPECT(ResolveUri("../../refpath", | 420 EXPECT(ResolveUri("../../refpath", "scheme://auth/a/b/c/d", &target_uri)); |
436 "scheme://auth/a/b/c/d", | |
437 &target_uri)); | |
438 EXPECT_STREQ("scheme://auth/a/refpath", target_uri); | 421 EXPECT_STREQ("scheme://auth/a/refpath", target_uri); |
439 } | 422 } |
440 | 423 |
441 | 424 |
442 TEST_CASE(ResolveUri_RemoveDots_RemoveTooManyDotDotSegments) { | 425 TEST_CASE(ResolveUri_RemoveDots_RemoveTooManyDotDotSegments) { |
443 const char* target_uri; | 426 const char* target_uri; |
444 EXPECT(ResolveUri("../../../../../../../../../refpath", | 427 EXPECT(ResolveUri("../../../../../../../../../refpath", |
445 "scheme://auth/a/b/c/d", | 428 "scheme://auth/a/b/c/d", &target_uri)); |
446 &target_uri)); | |
447 EXPECT_STREQ("scheme://auth/refpath", target_uri); | 429 EXPECT_STREQ("scheme://auth/refpath", target_uri); |
448 } | 430 } |
449 | 431 |
450 | 432 |
451 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsNothingLeft1) { | 433 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsNothingLeft1) { |
452 const char* target_uri; | 434 const char* target_uri; |
453 EXPECT(ResolveUri("../../../../..", | 435 EXPECT(ResolveUri("../../../../..", "scheme://auth/a/b/c/d", &target_uri)); |
454 "scheme://auth/a/b/c/d", | |
455 &target_uri)); | |
456 EXPECT_STREQ("scheme://auth/", target_uri); | 436 EXPECT_STREQ("scheme://auth/", target_uri); |
457 } | 437 } |
458 | 438 |
459 | 439 |
460 | |
461 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsNothingLeft2) { | 440 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsNothingLeft2) { |
462 const char* target_uri; | 441 const char* target_uri; |
463 EXPECT(ResolveUri(".", | 442 EXPECT(ResolveUri(".", "scheme://auth/", &target_uri)); |
464 "scheme://auth/", | |
465 &target_uri)); | |
466 EXPECT_STREQ("scheme://auth/", target_uri); | 443 EXPECT_STREQ("scheme://auth/", target_uri); |
467 } | 444 } |
468 | 445 |
469 | 446 |
470 | |
471 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsInitialPrefix) { | 447 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsInitialPrefix) { |
472 const char* target_uri; | 448 const char* target_uri; |
473 EXPECT(ResolveUri("../../../../refpath", | 449 EXPECT(ResolveUri("../../../../refpath", "scheme://auth", &target_uri)); |
474 "scheme://auth", | |
475 &target_uri)); | |
476 EXPECT_STREQ("scheme://auth/refpath", target_uri); | 450 EXPECT_STREQ("scheme://auth/refpath", target_uri); |
477 } | 451 } |
478 | 452 |
479 | 453 |
480 | |
481 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsMixed) { | 454 TEST_CASE(ResolveUri_RemoveDots_RemoveDotSegmentsMixed) { |
482 const char* target_uri; | 455 const char* target_uri; |
483 EXPECT(ResolveUri("../../1/./2/../3/4/../5/././6/../7", | 456 EXPECT(ResolveUri("../../1/./2/../3/4/../5/././6/../7", |
484 "scheme://auth/a/b/c/d/e", | 457 "scheme://auth/a/b/c/d/e", &target_uri)); |
485 &target_uri)); | |
486 EXPECT_STREQ("scheme://auth/a/b/1/3/5/7", target_uri); | 458 EXPECT_STREQ("scheme://auth/a/b/1/3/5/7", target_uri); |
487 } | 459 } |
488 | 460 |
489 | 461 |
490 TEST_CASE(ResolveUri_NormalizeEscapes_PathQueryFragment) { | 462 TEST_CASE(ResolveUri_NormalizeEscapes_PathQueryFragment) { |
491 const char* target_uri; | 463 const char* target_uri; |
492 EXPECT(ResolveUri("#A Fr%61gment", | 464 EXPECT(ResolveUri("#A Fr%61gment", |
493 "scheme:/This%09Is A P%61th?This%09Is A Qu%65ry", | 465 "scheme:/This%09Is A P%61th?This%09Is A Qu%65ry", |
494 &target_uri)); | 466 &target_uri)); |
495 EXPECT_STREQ( | 467 EXPECT_STREQ( |
496 "scheme:/This%09Is%20A%20Path?This%09Is%20A%20Query#A%20Fragment", | 468 "scheme:/This%09Is%20A%20Path?This%09Is%20A%20Query#A%20Fragment", |
497 target_uri); | 469 target_uri); |
498 } | 470 } |
499 | 471 |
500 | 472 |
501 TEST_CASE(ResolveUri_NormalizeEscapes_UppercaseHexPreferred) { | 473 TEST_CASE(ResolveUri_NormalizeEscapes_UppercaseHexPreferred) { |
502 const char* target_uri; | 474 const char* target_uri; |
503 EXPECT(ResolveUri("", | 475 EXPECT(ResolveUri("", "scheme:/%1b%1B", &target_uri)); |
504 "scheme:/%1b%1B", | 476 EXPECT_STREQ("scheme:/%1B%1B", target_uri); |
505 &target_uri)); | |
506 EXPECT_STREQ("scheme:/%1B%1B", | |
507 target_uri); | |
508 } | 477 } |
509 | 478 |
510 | 479 |
511 TEST_CASE(ResolveUri_NormalizeEscapes_Authority) { | 480 TEST_CASE(ResolveUri_NormalizeEscapes_Authority) { |
512 const char* target_uri; | 481 const char* target_uri; |
513 EXPECT(ResolveUri("", | 482 EXPECT( |
514 "scheme://UsEr N%61%4de@h%4FsT.c%6fm:80/", | 483 ResolveUri("", "scheme://UsEr N%61%4de@h%4FsT.c%6fm:80/", &target_uri)); |
515 &target_uri)); | |
516 // userinfo is normalized and case is preserved. host is normalized | 484 // userinfo is normalized and case is preserved. host is normalized |
517 // and lower-cased. | 485 // and lower-cased. |
518 EXPECT_STREQ("scheme://UsEr%20NaMe@host.com:80/", target_uri); | 486 EXPECT_STREQ("scheme://UsEr%20NaMe@host.com:80/", target_uri); |
519 } | 487 } |
520 | 488 |
521 | 489 |
522 TEST_CASE(ResolveUri_NormalizeEscapes_BrokenEscapeSequence) { | 490 TEST_CASE(ResolveUri_NormalizeEscapes_BrokenEscapeSequence) { |
523 const char* target_uri; | 491 const char* target_uri; |
524 EXPECT(ResolveUri("", | 492 EXPECT(ResolveUri("", "scheme:/%1g", &target_uri)); |
525 "scheme:/%1g", | |
526 &target_uri)); | |
527 // We don't change broken escape sequences. | 493 // We don't change broken escape sequences. |
528 EXPECT_STREQ("scheme:/%1g", | 494 EXPECT_STREQ("scheme:/%1g", target_uri); |
529 target_uri); | |
530 } | 495 } |
531 | 496 |
532 | 497 |
533 TEST_CASE(ResolveUri_DataUri) { | 498 TEST_CASE(ResolveUri_DataUri) { |
534 const char* data_uri = | 499 const char* data_uri = |
535 "data:application/dart;charset=utf-8,%20%20%20%20%20%20%20%20import%20%22d
art:isolate%22;%0A%0A%20%20%20%20%20%20%20%20import%20%22package:stream_channel/
stream_channel.dart%22;%0A%0A%20%20%20%20%20%20%20%20import%20%22package:test/sr
c/runner/plugin/remote_platform_helpers.dart%22;%0A%20%20%20%20%20%20%20%20impor
t%20%22package:test/src/runner/vm/catch_isolate_errors.dart%22;%0A%0A%20%20%20%2
0%20%20%20%20import%20%22file:///home/sra/xxxx/dev_compiler/test/all_tests.dart%
22%20as%20test;%0A%0A%20%20%20%20%20%20%20%20void%20main(_,%20SendPort%20message
)%20%7B%0A%20%20%20%20%20%20%20%20%20%20var%20channel%20=%20serializeSuite(()%20
%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20catchIsolateErrors();%0A%20%20%20%20%2
0%20%20%20%20%20%20%20return%20test.main;%0A%20%20%20%20%20%20%20%20%20%20%7D);%
0A%20%20%20%20%20%20%20%20%20%20new%20IsolateChannel.connectSend(message).pipe(c
hannel);%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20"; // NOLINT | 500 "data:application/" |
| 501 "dart;charset=utf-8,%20%20%20%20%20%20%20%20import%20%22dart:isolate%22;%" |
| 502 "0A%0A%20%20%20%20%20%20%20%20import%20%22package:stream_channel/" |
| 503 "stream_channel.dart%22;%0A%0A%20%20%20%20%20%20%20%20import%20%" |
| 504 "22package:test/src/runner/plugin/" |
| 505 "remote_platform_helpers.dart%22;%0A%20%20%20%20%20%20%20%20import%20%" |
| 506 "22package:test/src/runner/vm/" |
| 507 "catch_isolate_errors.dart%22;%0A%0A%20%20%20%20%20%20%20%20import%20%" |
| 508 "22file:///home/sra/xxxx/dev_compiler/test/" |
| 509 "all_tests.dart%22%20as%20test;%0A%0A%20%20%20%20%20%20%20%20void%20main(" |
| 510 "_,%20SendPort%20message)%20%7B%0A%20%20%20%20%20%20%20%20%20%20var%" |
| 511 "20channel%20=%20serializeSuite(()%20%7B%0A%20%20%20%20%20%20%20%20%20%" |
| 512 "20%20%20catchIsolateErrors();%0A%20%20%20%20%20%20%20%20%20%20%20%" |
| 513 "20return%20test.main;%0A%20%20%20%20%20%20%20%20%20%20%7D);%0A%20%20%20%" |
| 514 "20%20%20%20%20%20%20new%20IsolateChannel.connectSend(message).pipe(" |
| 515 "channel);%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20"; |
536 | 516 |
537 const char* target_uri; | 517 const char* target_uri; |
538 EXPECT(ResolveUri(data_uri, | 518 EXPECT(ResolveUri(data_uri, |
539 "bscheme://buser@bhost:11/base/path?baseQuery#bfragment", | 519 "bscheme://buser@bhost:11/base/path?baseQuery#bfragment", |
540 &target_uri)); | 520 &target_uri)); |
541 EXPECT_STREQ(data_uri, target_uri); | 521 EXPECT_STREQ(data_uri, target_uri); |
542 } | 522 } |
543 | 523 |
544 // dart:core Uri allows for the base url to be relative (no scheme, no | 524 // dart:core Uri allows for the base url to be relative (no scheme, no |
545 // authory, relative path) but this behavior is not in RFC 3986. We | 525 // authory, relative path) but this behavior is not in RFC 3986. We |
(...skipping 28 matching lines...) Expand all Loading... |
574 EXPECT(ResolveUri(uri, base_uri, &target_uri)); | 554 EXPECT(ResolveUri(uri, base_uri, &target_uri)); |
575 return target_uri; | 555 return target_uri; |
576 } | 556 } |
577 | 557 |
578 | 558 |
579 // This test is ported from sdk/tests/corelib/uri_test.dart (testUriPerRFCs). | 559 // This test is ported from sdk/tests/corelib/uri_test.dart (testUriPerRFCs). |
580 TEST_CASE(ResolveUri_TestUriPerRFCs) { | 560 TEST_CASE(ResolveUri_TestUriPerRFCs) { |
581 const char* base = "http://a/b/c/d;p?q"; | 561 const char* base = "http://a/b/c/d;p?q"; |
582 | 562 |
583 // From RFC 3986 | 563 // From RFC 3986 |
584 EXPECT_STREQ("g:h", TestResolve(base, "g:h")); | 564 EXPECT_STREQ("g:h", TestResolve(base, "g:h")); |
585 EXPECT_STREQ("http://a/b/c/g", TestResolve(base, "g")); | 565 EXPECT_STREQ("http://a/b/c/g", TestResolve(base, "g")); |
586 EXPECT_STREQ("http://a/b/c/g", TestResolve(base, "./g")); | 566 EXPECT_STREQ("http://a/b/c/g", TestResolve(base, "./g")); |
587 EXPECT_STREQ("http://a/b/c/g/", TestResolve(base, "g/")); | 567 EXPECT_STREQ("http://a/b/c/g/", TestResolve(base, "g/")); |
588 EXPECT_STREQ("http://a/g", TestResolve(base, "/g")); | 568 EXPECT_STREQ("http://a/g", TestResolve(base, "/g")); |
589 EXPECT_STREQ("http://g", TestResolve(base, "//g")); | 569 EXPECT_STREQ("http://g", TestResolve(base, "//g")); |
590 EXPECT_STREQ("http://a/b/c/d;p?y", TestResolve(base, "?y")); | 570 EXPECT_STREQ("http://a/b/c/d;p?y", TestResolve(base, "?y")); |
591 EXPECT_STREQ("http://a/b/c/g?y", TestResolve(base, "g?y")); | 571 EXPECT_STREQ("http://a/b/c/g?y", TestResolve(base, "g?y")); |
592 EXPECT_STREQ("http://a/b/c/d;p?q#s", TestResolve(base, "#s")); | 572 EXPECT_STREQ("http://a/b/c/d;p?q#s", TestResolve(base, "#s")); |
593 EXPECT_STREQ("http://a/b/c/g#s", TestResolve(base, "g#s")); | 573 EXPECT_STREQ("http://a/b/c/g#s", TestResolve(base, "g#s")); |
594 EXPECT_STREQ("http://a/b/c/g?y#s", TestResolve(base, "g?y#s")); | 574 EXPECT_STREQ("http://a/b/c/g?y#s", TestResolve(base, "g?y#s")); |
595 EXPECT_STREQ("http://a/b/c/;x", TestResolve(base, ";x")); | 575 EXPECT_STREQ("http://a/b/c/;x", TestResolve(base, ";x")); |
596 EXPECT_STREQ("http://a/b/c/g;x", TestResolve(base, "g;x")); | 576 EXPECT_STREQ("http://a/b/c/g;x", TestResolve(base, "g;x")); |
597 EXPECT_STREQ("http://a/b/c/g;x?y#s", TestResolve(base, "g;x?y#s")); | 577 EXPECT_STREQ("http://a/b/c/g;x?y#s", TestResolve(base, "g;x?y#s")); |
598 EXPECT_STREQ("http://a/b/c/d;p?q", TestResolve(base, "")); | 578 EXPECT_STREQ("http://a/b/c/d;p?q", TestResolve(base, "")); |
599 EXPECT_STREQ("http://a/b/c/", TestResolve(base, ".")); | 579 EXPECT_STREQ("http://a/b/c/", TestResolve(base, ".")); |
600 EXPECT_STREQ("http://a/b/c/", TestResolve(base, "./")); | 580 EXPECT_STREQ("http://a/b/c/", TestResolve(base, "./")); |
601 EXPECT_STREQ("http://a/b/", TestResolve(base, "..")); | 581 EXPECT_STREQ("http://a/b/", TestResolve(base, "..")); |
602 EXPECT_STREQ("http://a/b/", TestResolve(base, "../")); | 582 EXPECT_STREQ("http://a/b/", TestResolve(base, "../")); |
603 EXPECT_STREQ("http://a/b/g", TestResolve(base, "../g")); | 583 EXPECT_STREQ("http://a/b/g", TestResolve(base, "../g")); |
604 EXPECT_STREQ("http://a/", TestResolve(base, "../..")); | 584 EXPECT_STREQ("http://a/", TestResolve(base, "../..")); |
605 EXPECT_STREQ("http://a/", TestResolve(base, "../../")); | 585 EXPECT_STREQ("http://a/", TestResolve(base, "../../")); |
606 EXPECT_STREQ("http://a/g", TestResolve(base, "../../g")); | 586 EXPECT_STREQ("http://a/g", TestResolve(base, "../../g")); |
607 EXPECT_STREQ("http://a/g", TestResolve(base, "../../../g")); | 587 EXPECT_STREQ("http://a/g", TestResolve(base, "../../../g")); |
608 EXPECT_STREQ("http://a/g", TestResolve(base, "../../../../g")); | 588 EXPECT_STREQ("http://a/g", TestResolve(base, "../../../../g")); |
609 EXPECT_STREQ("http://a/g", TestResolve(base, "/./g")); | 589 EXPECT_STREQ("http://a/g", TestResolve(base, "/./g")); |
610 EXPECT_STREQ("http://a/g", TestResolve(base, "/../g")); | 590 EXPECT_STREQ("http://a/g", TestResolve(base, "/../g")); |
611 EXPECT_STREQ("http://a/b/c/g.", TestResolve(base, "g.")); | 591 EXPECT_STREQ("http://a/b/c/g.", TestResolve(base, "g.")); |
612 EXPECT_STREQ("http://a/b/c/.g", TestResolve(base, ".g")); | 592 EXPECT_STREQ("http://a/b/c/.g", TestResolve(base, ".g")); |
613 EXPECT_STREQ("http://a/b/c/g..", TestResolve(base, "g..")); | 593 EXPECT_STREQ("http://a/b/c/g..", TestResolve(base, "g..")); |
614 EXPECT_STREQ("http://a/b/c/..g", TestResolve(base, "..g")); | 594 EXPECT_STREQ("http://a/b/c/..g", TestResolve(base, "..g")); |
615 EXPECT_STREQ("http://a/b/g", TestResolve(base, "./../g")); | 595 EXPECT_STREQ("http://a/b/g", TestResolve(base, "./../g")); |
616 EXPECT_STREQ("http://a/b/c/g/", TestResolve(base, "./g/.")); | 596 EXPECT_STREQ("http://a/b/c/g/", TestResolve(base, "./g/.")); |
617 EXPECT_STREQ("http://a/b/c/g/h", TestResolve(base, "g/./h")); | 597 EXPECT_STREQ("http://a/b/c/g/h", TestResolve(base, "g/./h")); |
618 EXPECT_STREQ("http://a/b/c/h", TestResolve(base, "g/../h")); | 598 EXPECT_STREQ("http://a/b/c/h", TestResolve(base, "g/../h")); |
619 EXPECT_STREQ("http://a/b/c/g;x=1/y", TestResolve(base, "g;x=1/./y")); | 599 EXPECT_STREQ("http://a/b/c/g;x=1/y", TestResolve(base, "g;x=1/./y")); |
620 EXPECT_STREQ("http://a/b/c/y", TestResolve(base, "g;x=1/../y")); | 600 EXPECT_STREQ("http://a/b/c/y", TestResolve(base, "g;x=1/../y")); |
621 EXPECT_STREQ("http://a/b/c/g?y/./x", TestResolve(base, "g?y/./x")); | 601 EXPECT_STREQ("http://a/b/c/g?y/./x", TestResolve(base, "g?y/./x")); |
622 EXPECT_STREQ("http://a/b/c/g?y/../x", TestResolve(base, "g?y/../x")); | 602 EXPECT_STREQ("http://a/b/c/g?y/../x", TestResolve(base, "g?y/../x")); |
623 EXPECT_STREQ("http://a/b/c/g#s/./x", TestResolve(base, "g#s/./x")); | 603 EXPECT_STREQ("http://a/b/c/g#s/./x", TestResolve(base, "g#s/./x")); |
624 EXPECT_STREQ("http://a/b/c/g#s/../x", TestResolve(base, "g#s/../x")); | 604 EXPECT_STREQ("http://a/b/c/g#s/../x", TestResolve(base, "g#s/../x")); |
625 EXPECT_STREQ("http:g", TestResolve(base, "http:g")); | 605 EXPECT_STREQ("http:g", TestResolve(base, "http:g")); |
626 | 606 |
627 // Additional tests (not from RFC 3986). | 607 // Additional tests (not from RFC 3986). |
628 EXPECT_STREQ("http://a/b/g;p/h;s", TestResolve(base, "../g;p/h;s")); | 608 EXPECT_STREQ("http://a/b/g;p/h;s", TestResolve(base, "../g;p/h;s")); |
629 | 609 |
630 base = "s:a/b"; | 610 base = "s:a/b"; |
631 EXPECT_STREQ("s:/c", TestResolve(base, "../c")); | 611 EXPECT_STREQ("s:/c", TestResolve(base, "../c")); |
632 } | 612 } |
633 | 613 |
634 | 614 |
635 // This test is ported from sdk/tests/corelib/uri_test.dart (testResolvePath). | 615 // This test is ported from sdk/tests/corelib/uri_test.dart (testResolvePath). |
636 TEST_CASE(ResolveUri_MoreDotSegmentTests) { | 616 TEST_CASE(ResolveUri_MoreDotSegmentTests) { |
637 const char* base = "/"; | 617 const char* base = "/"; |
638 EXPECT_STREQ("/a/g", TestResolve(base, "/a/b/c/./../../g")); | 618 EXPECT_STREQ("/a/g", TestResolve(base, "/a/b/c/./../../g")); |
639 EXPECT_STREQ("/a/g", TestResolve(base, "/a/b/c/./../../g")); | 619 EXPECT_STREQ("/a/g", TestResolve(base, "/a/b/c/./../../g")); |
640 EXPECT_STREQ("/mid/6", TestResolve(base, "mid/content=5/../6")); | 620 EXPECT_STREQ("/mid/6", TestResolve(base, "mid/content=5/../6")); |
641 EXPECT_STREQ("/a/b/e", TestResolve(base, "a/b/c/d/../../e")); | 621 EXPECT_STREQ("/a/b/e", TestResolve(base, "a/b/c/d/../../e")); |
642 EXPECT_STREQ("/a/b/e", TestResolve(base, "../a/b/c/d/../../e")); | 622 EXPECT_STREQ("/a/b/e", TestResolve(base, "../a/b/c/d/../../e")); |
643 EXPECT_STREQ("/a/b/e", TestResolve(base, "./a/b/c/d/../../e")); | 623 EXPECT_STREQ("/a/b/e", TestResolve(base, "./a/b/c/d/../../e")); |
644 EXPECT_STREQ("/a/b/e", TestResolve(base, "../a/b/./c/d/../../e")); | 624 EXPECT_STREQ("/a/b/e", TestResolve(base, "../a/b/./c/d/../../e")); |
645 EXPECT_STREQ("/a/b/e", TestResolve(base, "./a/b/./c/d/../../e")); | 625 EXPECT_STREQ("/a/b/e", TestResolve(base, "./a/b/./c/d/../../e")); |
646 EXPECT_STREQ("/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/.")); | 626 EXPECT_STREQ("/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/.")); |
647 EXPECT_STREQ("/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/./.")); | 627 EXPECT_STREQ("/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/./.")); |
648 EXPECT_STREQ("/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/././.")); | 628 EXPECT_STREQ("/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/././.")); |
649 | 629 |
650 #define LH "http://localhost" | 630 #define LH "http://localhost" |
651 base = LH; | 631 base = LH; |
652 EXPECT_STREQ(LH "/a/g", TestResolve(base, "/a/b/c/./../../g")); | 632 EXPECT_STREQ(LH "/a/g", TestResolve(base, "/a/b/c/./../../g")); |
653 EXPECT_STREQ(LH "/a/g", TestResolve(base, "/a/b/c/./../../g")); | 633 EXPECT_STREQ(LH "/a/g", TestResolve(base, "/a/b/c/./../../g")); |
654 EXPECT_STREQ(LH "/mid/6", TestResolve(base, "mid/content=5/../6")); | 634 EXPECT_STREQ(LH "/mid/6", TestResolve(base, "mid/content=5/../6")); |
655 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "a/b/c/d/../../e")); | 635 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "a/b/c/d/../../e")); |
656 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "../a/b/c/d/../../e")); | 636 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "../a/b/c/d/../../e")); |
657 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "./a/b/c/d/../../e")); | 637 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "./a/b/c/d/../../e")); |
658 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "../a/b/./c/d/../../e")); | 638 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "../a/b/./c/d/../../e")); |
659 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "./a/b/./c/d/../../e")); | 639 EXPECT_STREQ(LH "/a/b/e", TestResolve(base, "./a/b/./c/d/../../e")); |
660 EXPECT_STREQ(LH "/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/.")); | 640 EXPECT_STREQ(LH "/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/.")); |
661 EXPECT_STREQ(LH "/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/./.")); | 641 EXPECT_STREQ(LH "/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/./.")); |
662 EXPECT_STREQ(LH "/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/././.")); | 642 EXPECT_STREQ(LH "/a/b/e/", TestResolve(base, "./a/b/./c/d/../../e/././.")); |
663 #undef LH | 643 #undef LH |
664 } | 644 } |
665 | 645 |
666 } // namespace dart | 646 } // namespace dart |
OLD | NEW |