[PATCH] D27527: Process tilde in llvm::sys::path::native.

Serge Pavlov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 1 01:50:12 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL296590: Process tilde in llvm::sys::path::native (authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D27527?vs=89973&id=90130#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27527

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


Index: llvm/trunk/lib/Support/Path.cpp
===================================================================
--- llvm/trunk/lib/Support/Path.cpp
+++ llvm/trunk/lib/Support/Path.cpp
@@ -556,8 +556,16 @@
 }
 
 void native(SmallVectorImpl<char> &Path) {
+  if (Path.empty())
+    return;
 #ifdef LLVM_ON_WIN32
   std::replace(Path.begin(), Path.end(), '/', '\\');
+  if (Path[0] == '~' && (Path.size() == 1 || is_separator(Path[1]))) {
+    SmallString<128> PathHome;
+    home_directory(PathHome);
+    PathHome.append(Path.begin() + 1, Path.end());
+    Path = PathHome;
+  }
 #else
   for (auto PI = Path.begin(), PE = Path.end(); PI < PE; ++PI) {
     if (*PI == '\\') {
Index: llvm/trunk/unittests/Support/Path.cpp
===================================================================
--- llvm/trunk/unittests/Support/Path.cpp
+++ llvm/trunk/unittests/Support/Path.cpp
@@ -968,6 +968,33 @@
   EXPECT_PATH_IS(Path6, "a\\", "a/");
 
 #undef EXPECT_PATH_IS
+
+#if defined(LLVM_ON_WIN32)
+  SmallString<64> PathHome;
+  path::home_directory(PathHome);
+
+  const char *Path7a = "~/aaa";
+  SmallString<64> Path7(Path7a);
+  path::native(Path7);
+  EXPECT_TRUE(Path7.endswith("\\aaa"));
+  EXPECT_TRUE(Path7.startswith(PathHome));
+  EXPECT_EQ(Path7.size(), PathHome.size() + strlen(Path7a + 1));
+
+  const char *Path8a = "~";
+  SmallString<64> Path8(Path8a);
+  path::native(Path8);
+  EXPECT_EQ(Path8, PathHome);
+
+  const char *Path9a = "~aaa";
+  SmallString<64> Path9(Path9a);
+  path::native(Path9);
+  EXPECT_EQ(Path9, "~aaa");
+
+  const char *Path10a = "aaa/~/b";
+  SmallString<64> Path10(Path10a);
+  path::native(Path10);
+  EXPECT_EQ(Path10, "aaa\\~\\b");
+#endif
 }
 
 TEST(Support, RemoveLeadingDotSlash) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27527.90130.patch
Type: text/x-patch
Size: 1718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170301/bccbdcc6/attachment.bin>


More information about the llvm-commits mailing list