| OLD | NEW |
| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 "\u00e9", "%C3%A9"); | 214 "\u00e9", "%C3%A9"); |
| 215 checkInvalidReplaced("http://r{}sum\{}.example.org", "\u00E9", "%C3%A9"); | 215 checkInvalidReplaced("http://r{}sum\{}.example.org", "\u00E9", "%C3%A9"); |
| 216 | 216 |
| 217 // Invalid characters. The characters must be rejected, even if normalizing | 217 // Invalid characters. The characters must be rejected, even if normalizing |
| 218 // the input would cause them to be valid (normalization happens after | 218 // the input would cause them to be valid (normalization happens after |
| 219 // validation). | 219 // validation). |
| 220 var invalidCharsAndReplacements = [ | 220 var invalidCharsAndReplacements = [ |
| 221 "\xe7", "%C3%A7", // Arbitrary non-ASCII letter | 221 "\xe7", "%C3%A7", // Arbitrary non-ASCII letter |
| 222 " ", "%20", // Space, not allowed anywhere. | 222 " ", "%20", // Space, not allowed anywhere. |
| 223 '"', "%22", // Quote, not allowed anywhere | 223 '"', "%22", // Quote, not allowed anywhere |
| 224 "<>", "%3C%3E", // Less/greater-than, not allowed anywhere. |
| 224 "\x7f", "%7F", // DEL, not allowed anywhere | 225 "\x7f", "%7F", // DEL, not allowed anywhere |
| 225 "\xdf", "%C3%9F", // German lower-case scharf-S. | 226 "\xdf", "%C3%9F", // German lower-case scharf-S. |
| 226 // Becomes ASCII when upper-cased. | 227 // Becomes ASCII when upper-cased. |
| 227 "\u0130", "%C4%B0", // Latin capital dotted I, | 228 "\u0130", "%C4%B0", // Latin capital dotted I, |
| 228 // becomes ASCII lower-case in Turkish. | 229 // becomes ASCII lower-case in Turkish. |
| 229 "%\uFB03", "%25%EF%AC%83", // % + Ligature ffi, | 230 "%\uFB03", "%25%EF%AC%83", // % + Ligature ffi, |
| 230 // becomes ASCII when upper-cased, | 231 // becomes ASCII when upper-cased, |
| 231 // should not be read as "%FFI". | 232 // should not be read as "%FFI". |
| 232 "\u212a", "%E2%84%AA", // Kelvin sign. Becomes ASCII when lower-cased. | 233 "\u212a", "%E2%84%AA", // Kelvin sign. Becomes ASCII when lower-cased. |
| 233 "%1g", "%251g", // Invalid escape. | 234 "%1g", "%251g", // Invalid escape. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 254 // No colon in host except before a port. | 255 // No colon in host except before a port. |
| 255 checkInvalid("s://x@x:x/"); | 256 checkInvalid("s://x@x:x/"); |
| 256 // At most one port. | 257 // At most one port. |
| 257 checkInvalid("s://x@x:9:9/"); | 258 checkInvalid("s://x@x:9:9/"); |
| 258 // At most one #. | 259 // At most one #. |
| 259 checkInvalid("s://x/x#foo#bar"); | 260 checkInvalid("s://x/x#foo#bar"); |
| 260 // Colon in host implies port and port may not be empty. | 261 // Colon in host implies port and port may not be empty. |
| 261 checkInvalid("s://:/"); | 262 checkInvalid("s://:/"); |
| 262 // @ not allowed in scheme. | 263 // @ not allowed in scheme. |
| 263 checkInvalid("s@://x:9/x?x#x"); | 264 checkInvalid("s@://x:9/x?x#x"); |
| 265 // ] not allowed alone in host. |
| 266 checkInvalid("s://xx]/"); |
| 267 // ] not allowed anywhere except in host. |
| 268 checkInvalid("s://xx/]"); |
| 269 checkInvalid("s://xx/?]"); |
| 270 checkInvalid("s://xx/#]"); |
| 271 checkInvalid("s:/]"); |
| 272 checkInvalid("s:/?]"); |
| 273 checkInvalid("s:/#]"); |
| 264 // IPv6 must be enclosed in [ and ] for Uri.parse. | 274 // IPv6 must be enclosed in [ and ] for Uri.parse. |
| 265 // It is allowed un-enclosed as argument to Uri(hist: ) because we don't | 275 // It is allowed un-enclosed as argument to `Uri(host:...)` because we don't |
| 266 // need to delimit. | 276 // need to delimit. |
| 267 checkInvalid("s://ffff::ffff:1234/"); | 277 checkInvalid("s://ffff::ffff:1234/"); |
| 268 } | 278 } |
| 269 | 279 |
| 270 void testNormalization() { | 280 void testNormalization() { |
| 271 // The Uri constructor and the Uri.parse function performs RFC-3986 | 281 // The Uri constructor and the Uri.parse function performs RFC-3986 |
| 272 // syntax based normalization. | 282 // syntax based normalization. |
| 273 | 283 |
| 274 var uri; | 284 var uri; |
| 275 | 285 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 String dump(Uri uri) { | 507 String dump(Uri uri) { |
| 498 return "URI: $uri\n" | 508 return "URI: $uri\n" |
| 499 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" | 509 " Scheme: ${uri.scheme} #${uri.scheme.length}\n" |
| 500 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" | 510 " User-info: ${uri.userInfo} #${uri.userInfo.length}\n" |
| 501 " Host: ${uri.host} #${uri.host.length}\n" | 511 " Host: ${uri.host} #${uri.host.length}\n" |
| 502 " Port: ${uri.port}\n" | 512 " Port: ${uri.port}\n" |
| 503 " Path: ${uri.path} #${uri.path.length}\n" | 513 " Path: ${uri.path} #${uri.path.length}\n" |
| 504 " Query: ${uri.query} #${uri.query.length}\n" | 514 " Query: ${uri.query} #${uri.query.length}\n" |
| 505 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; | 515 " Fragment: ${uri.fragment} #${uri.fragment.length}\n"; |
| 506 } | 516 } |
| OLD | NEW |