[PATCH] D46887: Fix llvm::sys::path::remove_dots() to return "." instead of an empty path.
Greg Clayton via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 15 13:56:48 PDT 2018
clayborg updated this revision to Diff 146913.
clayborg added a comment.
Added a test that tests for an empty path and making sure remove_dots leaves it empty.
https://reviews.llvm.org/D46887
Files:
lib/Support/Path.cpp
unittests/Support/Path.cpp
Index: unittests/Support/Path.cpp
===================================================================
--- unittests/Support/Path.cpp
+++ unittests/Support/Path.cpp
@@ -1146,7 +1146,7 @@
TEST(Support, RemoveDots) {
EXPECT_EQ("foolz\\wat",
remove_dots(".\\.\\\\foolz\\wat", false, path::Style::windows));
- EXPECT_EQ("", remove_dots(".\\\\\\\\\\", false, path::Style::windows));
+ EXPECT_EQ(".", remove_dots(".\\\\\\\\\\", false, path::Style::windows));
EXPECT_EQ("a\\..\\b\\c",
remove_dots(".\\a\\..\\b\\c", false, path::Style::windows));
@@ -1163,7 +1163,8 @@
EXPECT_EQ("foolz/wat",
remove_dots("././/foolz/wat", false, path::Style::posix));
- EXPECT_EQ("", remove_dots("./////", false, path::Style::posix));
+ EXPECT_EQ(".", remove_dots("./////", false, path::Style::posix));
+ EXPECT_EQ("", remove_dots("", false, path::Style::posix));
EXPECT_EQ("a/../b/c", remove_dots("./a/../b/c", false, path::Style::posix));
EXPECT_EQ("b/c", remove_dots("./a/../b/c", true, path::Style::posix));
Index: lib/Support/Path.cpp
===================================================================
--- lib/Support/Path.cpp
+++ lib/Support/Path.cpp
@@ -726,6 +726,10 @@
SmallString<256> buffer = path::root_path(path, style);
for (StringRef C : components)
path::append(buffer, style, C);
+ // If the path passed in wasn't empty, but results in a path that is empty
+ // (like ".", "./", or "foo/..") don't return an empty string, return a ".".
+ if (buffer.empty() && !path.empty())
+ buffer.append(1, '.');
return buffer;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46887.146913.patch
Type: text/x-patch
Size: 1598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180515/c89cae6b/attachment.bin>
More information about the llvm-commits
mailing list