[llvm-branch-commits] [lldb] dcdd231 - [lldb] Return the original path when tilde expansion fails.

Jonas Devlieghere via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Dec 2 16:06:23 PST 2020


Author: Jonas Devlieghere
Date: 2020-12-02T16:01:30-08:00
New Revision: dcdd231df6c7b6f4a635fe7941c1f87955328183

URL: https://github.com/llvm/llvm-project/commit/dcdd231df6c7b6f4a635fe7941c1f87955328183
DIFF: https://github.com/llvm/llvm-project/commit/dcdd231df6c7b6f4a635fe7941c1f87955328183.diff

LOG: [lldb] Return the original path when tilde expansion fails.

Differential revision: https://reviews.llvm.org/D92513

Added: 
    

Modified: 
    lldb/source/Utility/TildeExpressionResolver.cpp
    lldb/unittests/Utility/TildeExpressionResolverTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Utility/TildeExpressionResolver.cpp b/lldb/source/Utility/TildeExpressionResolver.cpp
index c8a0800cb807..75d9c47e656d 100644
--- a/lldb/source/Utility/TildeExpressionResolver.cpp
+++ b/lldb/source/Utility/TildeExpressionResolver.cpp
@@ -75,9 +75,8 @@ bool StandardTildeExpressionResolver::ResolvePartial(StringRef Expr,
 
 bool TildeExpressionResolver::ResolveFullPath(
     StringRef Expr, llvm::SmallVectorImpl<char> &Output) {
-  Output.clear();
   if (!Expr.startswith("~")) {
-    Output.append(Expr.begin(), Expr.end());
+    Output.assign(Expr.begin(), Expr.end());
     return false;
   }
 
@@ -85,8 +84,10 @@ bool TildeExpressionResolver::ResolveFullPath(
   StringRef Left =
       Expr.take_until([](char c) { return path::is_separator(c); });
 
-  if (!ResolveExact(Left, Output))
+  if (!ResolveExact(Left, Output)) {
+    Output.assign(Expr.begin(), Expr.end());
     return false;
+  }
 
   Output.append(Expr.begin() + Left.size(), Expr.end());
   return true;

diff  --git a/lldb/unittests/Utility/TildeExpressionResolverTest.cpp b/lldb/unittests/Utility/TildeExpressionResolverTest.cpp
index bc1ca7a44811..bcb7fdb8604d 100644
--- a/lldb/unittests/Utility/TildeExpressionResolverTest.cpp
+++ b/lldb/unittests/Utility/TildeExpressionResolverTest.cpp
@@ -31,6 +31,9 @@ TEST(TildeExpressionResolver, ResolveFullPath) {
   EXPECT_EQ("/lars", Result);
 
   ASSERT_FALSE(Resolver.ResolveFullPath("~Jaso", Result));
+  EXPECT_EQ("~Jaso", Result);
   ASSERT_FALSE(Resolver.ResolveFullPath("", Result));
+  EXPECT_EQ("", Result);
   ASSERT_FALSE(Resolver.ResolveFullPath("Jason", Result));
+  EXPECT_EQ("Jason", Result);
 }


        


More information about the llvm-branch-commits mailing list