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

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

Issue 1224263009: Do "path normalization" when creating a URI. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments. Created 5 years, 5 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
« no previous file with comments | « tests/corelib/uri_normalize_path_test.dart ('k') | tests/corelib/uri_test.dart » ('j') | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 6
7 testNormalizePath() { 7 testNormalizePath() {
8 test(String expected, String path) { 8 test(String expected, String path, {String scheme, String host}) {
9 var uri = new Uri(path: path); 9 var uri = new Uri(scheme: scheme, host: host, path: path);
10 Expect.equals(expected, uri.path);
11 Expect.equals(expected, uri.toString()); 10 Expect.equals(expected, uri.toString());
11 if (scheme == null && host == null) {
12 Expect.equals(expected, uri.path);
13 }
12 } 14 }
13 15
14 var unreserved = "-._~0123456789" 16 var unreserved = "-._~0123456789"
15 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 17 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
16 "abcdefghijklmnopqrstuvwxyz"; 18 "abcdefghijklmnopqrstuvwxyz";
17 19
18 test("A", "%41"); 20 test("A", "%41");
19 test("AB", "%41%42"); 21 test("AB", "%41%42");
20 test("%40AB", "%40%41%42"); 22 test("%40AB", "%40%41%42");
21 test("a", "%61"); 23 test("a", "%61");
22 test("ab", "%61%62"); 24 test("ab", "%61%62");
23 test("%60ab", "%60%61%62"); 25 test("%60ab", "%60%61%62");
24 test(unreserved, unreserved); 26 test(unreserved, unreserved);
25 27
26 var x = new StringBuffer(); 28 var x = new StringBuffer();
27 for (int i = 32; i < 128; i++) { 29 for (int i = 32; i < 128; i++) {
28 if (unreserved.indexOf(new String.fromCharCode(i)) != -1) { 30 if (unreserved.indexOf(new String.fromCharCode(i)) != -1) {
29 x.writeCharCode(i); 31 x.writeCharCode(i);
30 } else { 32 } else {
31 x.write("%"); 33 x.write("%");
32 x.write(i.toRadixString(16)); 34 x.write(i.toRadixString(16));
33 } 35 }
34 } 36 }
35 print(x.toString().toUpperCase());
36 Expect.equals(x.toString().toUpperCase(), 37 Expect.equals(x.toString().toUpperCase(),
37 new Uri(path: x.toString()).toString().toUpperCase()); 38 new Uri(path: x.toString()).toString().toUpperCase());
39
40 // Normalized paths.
41
42 // Full absolute path normalization for absolute paths.
43 test("/a/b/c/", "/../a/./b/z/../c/d/..");
44 test("/a/b/c/", "/./a/b/c/");
45 test("/a/b/c/", "/./../a/b/c/");
46 test("/a/b/c/", "/./../a/b/c/.");
47 test("/a/b/c/", "/./../a/b/c/z/./..");
48 test("/", "/a/..");
49 // Full absolute path normalization for URIs with scheme.
50 test("s:a/b/c/", "../a/./b/z/../c/d/..", scheme: "s");
51 test("s:a/b/c/", "./a/b/c/", scheme: "s");
52 test("s:a/b/c/", "./../a/b/c/", scheme: "s");
53 test("s:a/b/c/", "./../a/b/c/.", scheme: "s");
54 test("s:a/b/c/", "./../a/b/c/z/./..", scheme: "s");
55 test("s:/", "/a/..", scheme: "s");
56 test("s:/", "a/..", scheme: "s");
57 // Full absolute path normalization for URIs with authority.
58 test("//h/a/b/c/", "../a/./b/z/../c/d/..", host: "h");
59 test("//h/a/b/c/", "./a/b/c/", host: "h");
60 test("//h/a/b/c/", "./../a/b/c/", host: "h");
61 test("//h/a/b/c/", "./../a/b/c/.", host: "h");
62 test("//h/a/b/c/", "./../a/b/c/z/./..", host: "h");
63 test("//h/", "/a/..", host: "h");
64 test("//h/", "a/..", host: "h");
65 // Partial relative normalization (allowing leading .. or ./ for current dir).
66 test("../a/b/c/", "../a/./b/z/../c/d/..");
67 test("a/b/c/", "./a/b/c/");
68 test("../a/b/c/", "./../a/b/c/");
69 test("../a/b/c/", "./../a/b/c/.");
70 test("../a/b/c/", "./../a/b/c/z/./..");
71 test("/", "/a/..");
72 test("./", "a/..");
38 } 73 }
39 74
40 main() { 75 main() {
41 testNormalizePath(); 76 testNormalizePath();
42 } 77 }
OLDNEW
« no previous file with comments | « tests/corelib/uri_normalize_path_test.dart ('k') | tests/corelib/uri_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698