| 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..27ccab2ea4d0db453c217d1921db71729de58aac 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,134 @@ TEST(FilesystemUtils, NormalizePath) {
|
| input = "//foo/bar/";
|
| NormalizePath(&input);
|
| EXPECT_EQ("//foo/bar/", input);
|
| +
|
| +#if defined(OS_WIN)
|
| + // Go above and outside of the source root.
|
| + input = "//../foo";
|
| + NormalizePath(&input, "/C:/source/root");
|
| + EXPECT_EQ("/C:/source/foo", input);
|
| +
|
| + input = "//../foo";
|
| + NormalizePath(&input, "C:\\source\\root");
|
| + EXPECT_EQ("/C:/source/foo", input);
|
| +
|
| + input = "//../";
|
| + NormalizePath(&input, "/C:/source/root");
|
| + EXPECT_EQ("/C:/source/", input);
|
| +
|
| + input = "//../foo.txt";
|
| + NormalizePath(&input, "/C:/source/root");
|
| + EXPECT_EQ("/C:/source/foo.txt", input);
|
| +
|
| + input = "//../foo/bar/";
|
| + NormalizePath(&input, "/C:/source/root");
|
| + EXPECT_EQ("/C:/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, "/C:/source/root");
|
| + EXPECT_EQ("/C:/source/root/foo", input);
|
| +
|
| + input = "//../root/foo/bar/";
|
| + NormalizePath(&input, "/C:/source/root");
|
| + EXPECT_EQ("/C:/source/root/foo/bar/", input);
|
| +
|
| + // Stay inside the source root
|
| + input = "//foo/bar";
|
| + NormalizePath(&input, "/C:/source/root");
|
| + EXPECT_EQ("//foo/bar", input);
|
| +
|
| + input = "//foo/bar/";
|
| + NormalizePath(&input, "/C:/source/root");
|
| + EXPECT_EQ("//foo/bar/", input);
|
| +
|
| + // The path should not go above the system root. Note that on Windows, this
|
| + // will consume the drive (C:).
|
| + input = "//../../../../../foo/bar";
|
| + NormalizePath(&input, "/C:/source/root");
|
| + EXPECT_EQ("/foo/bar", input);
|
| +
|
| + // Test when the source root is the letter drive.
|
| + input = "//../foo";
|
| + NormalizePath(&input, "/C:");
|
| + EXPECT_EQ("/foo", input);
|
| +
|
| + input = "//../foo";
|
| + NormalizePath(&input, "C:");
|
| + EXPECT_EQ("/foo", input);
|
| +
|
| + input = "//../foo";
|
| + NormalizePath(&input, "/");
|
| + EXPECT_EQ("/foo", input);
|
| +
|
| + input = "//../";
|
| + NormalizePath(&input, "\\C:");
|
| + EXPECT_EQ("/", input);
|
| +
|
| + input = "//../foo.txt";
|
| + NormalizePath(&input, "/C:");
|
| + EXPECT_EQ("/foo.txt", input);
|
| +#else
|
| + // Go above and outside of the source root.
|
| + 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);
|
| +
|
| + // Test when the source root is the system root.
|
| + input = "//../foo/bar/";
|
| + NormalizePath(&input, "/");
|
| + EXPECT_EQ("/foo/bar/", input);
|
| +
|
| + input = "//../";
|
| + NormalizePath(&input, "/");
|
| + EXPECT_EQ("/", input);
|
| +
|
| + input = "//../foo.txt";
|
| + NormalizePath(&input, "/");
|
| + EXPECT_EQ("/foo.txt", input);
|
| +
|
| +#endif
|
| }
|
|
|
| TEST(FilesystemUtils, RebasePath) {
|
|
|