[PATCH] D25561: Do not delete leading ../ in remove_dots.

Eric Liu via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 13 08:16:30 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL284129: Do not delete leading ../ in remove_dots. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D25561?vs=74521&id=74523#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25561

Files:
  llvm/trunk/include/llvm/Support/Path.h
  llvm/trunk/lib/Support/Path.cpp
  llvm/trunk/unittests/Support/Path.cpp


Index: llvm/trunk/unittests/Support/Path.cpp
===================================================================
--- llvm/trunk/unittests/Support/Path.cpp
+++ llvm/trunk/unittests/Support/Path.cpp
@@ -965,6 +965,8 @@
   EXPECT_EQ("a\\..\\b\\c", remove_dots(".\\a\\..\\b\\c", false));
   EXPECT_EQ("b\\c", remove_dots(".\\a\\..\\b\\c", 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));
 
   SmallString<64> Path1(".\\.\\c");
   EXPECT_TRUE(path::remove_dots(Path1, true));
@@ -976,6 +978,8 @@
   EXPECT_EQ("a/../b/c", remove_dots("./a/../b/c", false));
   EXPECT_EQ("b/c", remove_dots("./a/../b/c", 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));
 
   SmallString<64> Path1("././c");
   EXPECT_TRUE(path::remove_dots(Path1, true));
Index: llvm/trunk/include/llvm/Support/Path.h
===================================================================
--- llvm/trunk/include/llvm/Support/Path.h
+++ llvm/trunk/include/llvm/Support/Path.h
@@ -445,7 +445,8 @@
 /// @brief In-place remove any './' and optionally '../' components from a path.
 ///
 /// @param path processed path
-/// @param remove_dot_dot specify if '../' should be removed
+/// @param remove_dot_dot specify if '../' (except for leading "../") should be
+/// removed
 /// @result True if path was changed
 bool remove_dots(SmallVectorImpl<char> &path, bool remove_dot_dot = false);
 
Index: llvm/trunk/lib/Support/Path.cpp
===================================================================
--- llvm/trunk/lib/Support/Path.cpp
+++ llvm/trunk/lib/Support/Path.cpp
@@ -707,12 +707,11 @@
   for (StringRef C : llvm::make_range(path::begin(rel), path::end(rel))) {
     if (C == ".")
       continue;
-    if (remove_dot_dot) {
-      if (C == "..") {
-        if (!components.empty())
-          components.pop_back();
-        continue;
-      }
+    // Leading ".." will remain in the path.
+    if (remove_dot_dot && C == ".." && !components.empty() &&
+        components.back() != "..") {
+      components.pop_back();
+      continue;
     }
     components.push_back(C);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25561.74523.patch
Type: text/x-patch
Size: 2311 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161013/f74cb59a/attachment.bin>


More information about the llvm-commits mailing list