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

Unified Diff: tools/gn/filesystem_utils_unittest.cc

Issue 1455203002: [GN] Add support to rebase_path to resolve paths above the source root. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: . Created 5 years, 1 month 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
Index: tools/gn/filesystem_utils_unittest.cc
diff --git a/tools/gn/filesystem_utils_unittest.cc b/tools/gn/filesystem_utils_unittest.cc
index 9f89512cfa29f1260d20488e9a67a6feaed4e448..6c3ebe22a213b5923c5dc371dfed15bb76d3e67e 100644
--- a/tools/gn/filesystem_utils_unittest.cc
+++ b/tools/gn/filesystem_utils_unittest.cc
@@ -204,7 +204,7 @@ TEST(FilesystemUtils, NormalizePath) {
NormalizePath(&input);
EXPECT_EQ("../bar", input);
- input = "/../foo"; // Don't go aboe the root dir.
+ input = "/../foo"; // Don't go above the root dir.
NormalizePath(&input);
EXPECT_EQ("/foo", input);
@@ -241,6 +241,53 @@ TEST(FilesystemUtils, NormalizePath) {
input = "//foo/bar/";
NormalizePath(&input);
EXPECT_EQ("//foo/bar/", input);
+
+ // Go above and outside of the source root.
+ input = "//../foo";
+ NormalizePath(&input, "/source/root");
+ EXPECT_EQ("/source/foo", input);
+
+ input = "//../foo";
+ NormalizePath(&input, "/source/root/");
+ EXPECT_EQ("/source/foo", input);
+
+ input = "//../";
+ NormalizePath(&input, "/source/root/");
+ EXPECT_EQ("/source/", input);
+
+ input = "//../foo.txt";
+ NormalizePath(&input, "/source/root");
+ EXPECT_EQ("/source/foo.txt", input);
+
+ input = "//../foo/bar/";
+ NormalizePath(&input, "/source/root");
+ EXPECT_EQ("/source/foo/bar/", input);
+
+ // Go above and back into the source root. This should return a system-
+ // absolute path. We could arguably return this as a source-absolute path,
+ // but that would require additional handling to account for a rare edge
+ // case.
+ input = "//../root/foo";
+ NormalizePath(&input, "/source/root");
+ EXPECT_EQ("/source/root/foo", input);
+
+ input = "//../root/foo/bar/";
+ NormalizePath(&input, "/source/root");
+ EXPECT_EQ("/source/root/foo/bar/", input);
+
+ // Stay inside the source root
+ input = "//foo/bar";
+ NormalizePath(&input, "/source/root");
+ EXPECT_EQ("//foo/bar", input);
+
+ input = "//foo/bar/";
+ NormalizePath(&input, "/source/root");
+ EXPECT_EQ("//foo/bar/", input);
+
+ // The path should not go above the system root.
+ input = "//../../../../../foo/bar";
+ NormalizePath(&input, "/source/root");
+ EXPECT_EQ("/foo/bar", input);
}
brettw 2015/12/01 01:21:22 Can you add a test to SourceDir that checks this i
slan 2015/12/01 22:15:03 Done.
TEST(FilesystemUtils, RebasePath) {

Powered by Google App Engine
This is Rietveld 408576698