<div dir="ltr">Nice! I like Go's Path.Clean and I'm happy to see this patch has landed.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 17, 2016 at 6:28 AM, Benjamin Kramer via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Mon Oct 17 08:28:21 2016<br>
New Revision: 284384<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=284384&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=284384&view=rev</a><br>
Log:<br>
[Support] remove_dots: Remove .. from absolute paths.<br>
<br>
/../foo is still a proper path after removing the dotdot. This should<br>
now finally match <a href="https://9p.io/sys/doc/lexnames.html" rel="noreferrer" target="_blank">https://9p.io/sys/doc/<wbr>lexnames.html</a> [Cleaning names].<br>
<br>
Modified:<br>
    llvm/trunk/lib/Support/Path.<wbr>cpp<br>
    llvm/trunk/unittests/Support/<wbr>Path.cpp<br>
<br>
Modified: llvm/trunk/lib/Support/Path.<wbr>cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Path.cpp?rev=284384&r1=284383&r2=284384&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Support/Path.cpp?rev=284384&<wbr>r1=284383&r2=284384&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/lib/Support/Path.<wbr>cpp (original)<br>
+++ llvm/trunk/lib/Support/Path.<wbr>cpp Mon Oct 17 08:28:21 2016<br>
@@ -707,11 +707,14 @@ static SmallString<256> remove_dots(Stri<br>
   for (StringRef C : llvm::make_range(path::begin(<wbr>rel), path::end(rel))) {<br>
     if (C == ".")<br>
       continue;<br>
-    // Leading ".." will remain in the path.<br>
-    if (remove_dot_dot && C == ".." && !components.empty() &&<br>
-        components.back() != "..") {<br>
-      components.pop_back();<br>
-      continue;<br>
+    // Leading ".." will remain in the path unless it's at the root.<br>
+    if (remove_dot_dot && C == "..") {<br>
+      if (!components.empty() && components.back() != "..") {<br>
+        components.pop_back();<br>
+        continue;<br>
+      }<br>
+      if (path::is_absolute(path))<br>
+        continue;<br>
     }<br>
     components.push_back(C);<br>
   }<br>
<br>
Modified: llvm/trunk/unittests/Support/<wbr>Path.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=284384&r1=284383&r2=284384&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/unittests/<wbr>Support/Path.cpp?rev=284384&<wbr>r1=284383&r2=284384&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- llvm/trunk/unittests/Support/<wbr>Path.cpp (original)<br>
+++ llvm/trunk/unittests/Support/<wbr>Path.cpp Mon Oct 17 08:28:21 2016<br>
@@ -969,6 +969,8 @@ TEST(Support, RemoveDots) {<br>
   EXPECT_EQ("c", remove_dots(".\\.\\c", true));<br>
   EXPECT_EQ("..\\a\\c", remove_dots("..\\a\\b\\..\\c", true));<br>
   EXPECT_EQ("..\\..\\a\\c", remove_dots("..\\..\\a\\b\\..\<wbr>\c", true));<br>
+  EXPECT_EQ("\\a\\c", remove_dots("\\..\\..\\a\\c", true));<br>
+  EXPECT_EQ("\\a\\c", remove_dots("\\..\\a\\b\\\\..\<wbr>\.\\.\\\\c", true));<br>
<br>
   SmallString<64> Path1(".\\.\\c");<br>
   EXPECT_TRUE(path::remove_dots(<wbr>Path1, true));<br>
@@ -982,6 +984,8 @@ TEST(Support, RemoveDots) {<br>
   EXPECT_EQ("c", remove_dots("././c", true));<br>
   EXPECT_EQ("../a/c", remove_dots("../a/b/../c", true));<br>
   EXPECT_EQ("../../a/c", remove_dots("../../a/b/../c", true));<br>
+  EXPECT_EQ("/a/c", remove_dots("/../../a/c", true));<br>
+  EXPECT_EQ("/a/c", remove_dots("/../a/b//../././/<wbr>c", true));<br>
<br>
   SmallString<64> Path1("././c");<br>
   EXPECT_TRUE(path::remove_dots(<wbr>Path1, true));<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>