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

Side by Side Diff: tests/corelib/uri_test.dart

Issue 347393003: Fix bugs in Uri: Allow empty port, handle path starting with "//" in toString. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library uriTest; 5 library uriTest;
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 testUri(String uri, bool isAbsolute) { 10 testUri(String uri, bool isAbsolute) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 140
141 void testValidCharacters() { 141 void testValidCharacters() {
142 // test that all valid characters are accepted. 142 // test that all valid characters are accepted.
143 143
144 for (var scheme in ["", "$SCHEMECHAR$SCHEMECHAR:"]) { 144 for (var scheme in ["", "$SCHEMECHAR$SCHEMECHAR:"]) {
145 for (var userinfo in ["", "@", "$USERINFOCHAR$USERINFOCHAR@", 145 for (var userinfo in ["", "@", "$USERINFOCHAR$USERINFOCHAR@",
146 "$USERINFOCHAR:$DIGIT@"]) { 146 "$USERINFOCHAR:$DIGIT@"]) {
147 for (var host in ["", "$REGNAMECHAR$REGNAMECHAR", 147 for (var host in ["", "$REGNAMECHAR$REGNAMECHAR",
148 "255.255.255.256", // valid reg-name. 148 "255.255.255.256", // valid reg-name.
149 "[ffff::ffff:ffff]", "[ffff::255.255.255.255]"]) { 149 "[ffff::ffff:ffff]", "[ffff::255.255.255.255]"]) {
150 for (var port in ["", ":$DIGIT$DIGIT"]) { 150 for (var port in ["", ":", ":$DIGIT$DIGIT"]) {
151 var auth = "$userinfo$host$port"; 151 var auth = "$userinfo$host$port";
152 if (auth.isNotEmpty) auth = "//$auth"; 152 if (auth.isNotEmpty) auth = "//$auth";
153 var paths = ["", "/", "/$PCHAR", "/$PCHAR/"]; // Absolute or empty. 153 var paths = ["", "/", "/$PCHAR", "/$PCHAR/"]; // Absolute or empty.
154 if (auth.isNotEmpty) { 154 if (auth.isNotEmpty) {
155 // Initial segment may be empty. 155 // Initial segment may be empty.
156 paths..add("//$PCHAR"); 156 paths..add("//$PCHAR");
157 } else { 157 } else {
158 // Path may begin with non-slash. 158 // Path may begin with non-slash.
159 if (scheme.isEmpty) { 159 if (scheme.isEmpty) {
160 // Initial segment must not contain colon. 160 // Initial segment must not contain colon.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 251 }
252 252
253 // At most one @ in userinfo. 253 // At most one @ in userinfo.
254 checkInvalid("s://x@x@x.x/"); 254 checkInvalid("s://x@x@x.x/");
255 // No colon in host except before a port. 255 // No colon in host except before a port.
256 checkInvalid("s://x@x:x/"); 256 checkInvalid("s://x@x:x/");
257 // At most one port. 257 // At most one port.
258 checkInvalid("s://x@x:9:9/"); 258 checkInvalid("s://x@x:9:9/");
259 // At most one #. 259 // At most one #.
260 checkInvalid("s://x/x#foo#bar"); 260 checkInvalid("s://x/x#foo#bar");
261 // Colon in host implies port and port may not be empty.
262 checkInvalid("s://:/");
263 // @ not allowed in scheme. 261 // @ not allowed in scheme.
264 checkInvalid("s@://x:9/x?x#x"); 262 checkInvalid("s@://x:9/x?x#x");
265 // ] not allowed alone in host. 263 // ] not allowed alone in host.
266 checkInvalid("s://xx]/"); 264 checkInvalid("s://xx]/");
267 // ] not allowed anywhere except in host. 265 // ] not allowed anywhere except in host.
268 checkInvalid("s://xx/]"); 266 checkInvalid("s://xx/]");
269 checkInvalid("s://xx/?]"); 267 checkInvalid("s://xx/?]");
270 checkInvalid("s://xx/#]"); 268 checkInvalid("s://xx/#]");
271 checkInvalid("s:/]"); 269 checkInvalid("s:/]");
272 checkInvalid("s:/?]"); 270 checkInvalid("s:/?]");
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 Expect.equals("xxxxxxxxa", uri.host); 331 Expect.equals("xxxxxxxxa", uri.host);
334 332
335 uri = Uri.parse("x://%61xxxxxxxx/"); 333 uri = Uri.parse("x://%61xxxxxxxx/");
336 Expect.equals("axxxxxxxx", uri.host); 334 Expect.equals("axxxxxxxx", uri.host);
337 335
338 uri = Uri.parse("x://X/"); 336 uri = Uri.parse("x://X/");
339 Expect.equals("x", uri.host); 337 Expect.equals("x", uri.host);
340 338
341 uri = Uri.parse("x://%61/"); 339 uri = Uri.parse("x://%61/");
342 Expect.equals("a", uri.host); 340 Expect.equals("a", uri.host);
341
342 uri = new Uri(scheme: "x", path: "//y");
343 Expect.equals("//y", uri.path);
344 Expect.equals("x:////y", uri.toString());
345
346 uri = new Uri(scheme: "file", path: "//y");
347 Expect.equals("//y", uri.path);
348 Expect.equals("file:////y", uri.toString());
349
350 // File scheme noralizes to always showing authority, even if empty.
351 uri = new Uri(scheme: "file", path: "/y");
352 Expect.equals("file:///y", uri.toString());
353 uri = new Uri(scheme: "file", path: "y");
354 Expect.equals("file:///y", uri.toString());
343 } 355 }
344 356
345 main() { 357 main() {
346 testUri("http:", true); 358 testUri("http:", true);
347 testUri("file://", true); 359 testUri("file://", true);
348 testUri("file", false); 360 testUri("file", false);
349 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true); 361 testUri("http://user@example.com:8080/fisk?query=89&hest=silas", true);
350 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment", 362 testUri("http://user@example.com:8080/fisk?query=89&hest=silas#fragment",
351 false); 363 false);
352 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment", 364 Expect.stringEquals("http://user@example.com/a/b/c?query#fragment",
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 testEncodeDecodeComponent(s, "%F0%90%80%80"); 507 testEncodeDecodeComponent(s, "%F0%90%80%80");
496 testEncodeDecodeQueryComponent("A + B", "A+%2B+B", "A+%2B+B", "A+%2B+B"); 508 testEncodeDecodeQueryComponent("A + B", "A+%2B+B", "A+%2B+B", "A+%2B+B");
497 testEncodeDecodeQueryComponent( 509 testEncodeDecodeQueryComponent(
498 "æ ø å", "%C3%A6+%C3%B8+%C3%A5", "%E6+%F8+%E5", null); 510 "æ ø å", "%C3%A6+%C3%B8+%C3%A5", "%E6+%F8+%E5", null);
499 testEncodeDecodeComponent(nonAscii, nonAsciiEncoding); 511 testEncodeDecodeComponent(nonAscii, nonAsciiEncoding);
500 512
501 // Invalid URI - : and @ is swapped, port ("host") should be numeric. 513 // Invalid URI - : and @ is swapped, port ("host") should be numeric.
502 Expect.throws( 514 Expect.throws(
503 () => Uri.parse("file://user@password:host/path"), 515 () => Uri.parse("file://user@password:host/path"),
504 (e) => e is FormatException); 516 (e) => e is FormatException);
517
518 testValidCharacters();
519 testInvalidUrls();
520 testNormalization();
505 } 521 }
506 522
507 String dump(Uri uri) { 523 String dump(Uri uri) {
508 return "URI: $uri\n" 524 return "URI: $uri\n"
509 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" 525 " Scheme: ${uri.scheme} #${uri.scheme.length}\n"
510 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" 526 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n"
511 " Host: ${uri.host} #${uri.host.length}\n" 527 " Host: ${uri.host} #${uri.host.length}\n"
512 " Port: ${uri.port}\n" 528 " Port: ${uri.port}\n"
513 " Path: ${uri.path} #${uri.path.length}\n" 529 " Path: ${uri.path} #${uri.path.length}\n"
514 " Query: ${uri.query} #${uri.query.length}\n" 530 " Query: ${uri.query} #${uri.query.length}\n"
515 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; 531 " Fragment: ${uri.fragment} #${uri.fragment.length}\n";
516 } 532 }
OLDNEW
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698