for (StringRef C : llvm::make_range(path::begin(rel), path::end(rel))) {
if (C == ".")
continue;
- // Leading ".." will remain in the path.
- if (remove_dot_dot && C == ".." && !components.empty() &&
- components.back() != "..") {
- components.pop_back();
- continue;
+ // Leading ".." will remain in the path unless it's at the root.
+ if (remove_dot_dot && C == "..") {
+ if (!components.empty() && components.back() != "..") {
+ components.pop_back();
+ continue;
+ }
+ if (path::is_absolute(path))
+ continue;
}
components.push_back(C);
}
EXPECT_EQ("c", remove_dots(".\\.\\c", true));
EXPECT_EQ("..\\a\\c", remove_dots("..\\a\\b\\..\\c", true));
EXPECT_EQ("..\\..\\a\\c", remove_dots("..\\..\\a\\b\\..\\c", true));
+ EXPECT_EQ("\\a\\c", remove_dots("\\..\\..\\a\\c", true));
+ EXPECT_EQ("\\a\\c", remove_dots("\\..\\a\\b\\\\..\\.\\.\\\\c", true));
SmallString<64> Path1(".\\.\\c");
EXPECT_TRUE(path::remove_dots(Path1, true));
EXPECT_EQ("c", remove_dots("././c", true));
EXPECT_EQ("../a/c", remove_dots("../a/b/../c", true));
EXPECT_EQ("../../a/c", remove_dots("../../a/b/../c", true));
+ EXPECT_EQ("/a/c", remove_dots("/../../a/c", true));
+ EXPECT_EQ("/a/c", remove_dots("/../a/b//../././/c", true));
SmallString<64> Path1("././c");
EXPECT_TRUE(path::remove_dots(Path1, true));