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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/corelib/uri_normalize_test.dart
diff --git a/tests/corelib/uri_normalize_test.dart b/tests/corelib/uri_normalize_test.dart
index 91bbe10f1c1bc8b047012531a1ec4288d0240103..5c2f8140c0800bbc8459aa3f8843c8e5edd3d2f6 100644
--- a/tests/corelib/uri_normalize_test.dart
+++ b/tests/corelib/uri_normalize_test.dart
@@ -5,10 +5,12 @@
import "package:expect/expect.dart";
testNormalizePath() {
- test(String expected, String path) {
- var uri = new Uri(path: path);
- Expect.equals(expected, uri.path);
+ test(String expected, String path, {String scheme, String host}) {
+ var uri = new Uri(scheme: scheme, host: host, path: path);
Expect.equals(expected, uri.toString());
+ if (scheme == null && host == null) {
+ Expect.equals(expected, uri.path);
+ }
}
var unreserved = "-._~0123456789"
@@ -32,9 +34,42 @@ testNormalizePath() {
x.write(i.toRadixString(16));
}
}
- print(x.toString().toUpperCase());
Expect.equals(x.toString().toUpperCase(),
new Uri(path: x.toString()).toString().toUpperCase());
+
+ // Normalized paths.
+
+ // Full absolute path normalization for absolute paths.
+ test("/a/b/c/", "/../a/./b/z/../c/d/..");
+ test("/a/b/c/", "/./a/b/c/");
+ test("/a/b/c/", "/./../a/b/c/");
+ test("/a/b/c/", "/./../a/b/c/.");
+ test("/a/b/c/", "/./../a/b/c/z/./..");
+ test("/", "/a/..");
+ // Full absolute path normalization for URIs with scheme.
+ test("s:a/b/c/", "../a/./b/z/../c/d/..", scheme: "s");
+ test("s:a/b/c/", "./a/b/c/", scheme: "s");
+ test("s:a/b/c/", "./../a/b/c/", scheme: "s");
+ test("s:a/b/c/", "./../a/b/c/.", scheme: "s");
+ test("s:a/b/c/", "./../a/b/c/z/./..", scheme: "s");
+ test("s:/", "/a/..", scheme: "s");
+ test("s:/", "a/..", scheme: "s");
+ // Full absolute path normalization for URIs with authority.
+ test("//h/a/b/c/", "../a/./b/z/../c/d/..", host: "h");
+ test("//h/a/b/c/", "./a/b/c/", host: "h");
+ test("//h/a/b/c/", "./../a/b/c/", host: "h");
+ test("//h/a/b/c/", "./../a/b/c/.", host: "h");
+ test("//h/a/b/c/", "./../a/b/c/z/./..", host: "h");
+ test("//h/", "/a/..", host: "h");
+ test("//h/", "a/..", host: "h");
+ // Partial relative normalization (allowing leading .. or ./ for current dir).
+ test("../a/b/c/", "../a/./b/z/../c/d/..");
+ test("a/b/c/", "./a/b/c/");
+ test("../a/b/c/", "./../a/b/c/");
+ test("../a/b/c/", "./../a/b/c/.");
+ test("../a/b/c/", "./../a/b/c/z/./..");
+ test("/", "/a/..");
+ test("./", "a/..");
}
main() {
« 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