From f72ae5cba1d625301aa8a668a3d54ec3ac5b7806 Mon Sep 17 00:00:00 2001 From: Jaroslav Sevcik Date: Sat, 4 Dec 2021 21:32:09 +0100 Subject: [PATCH] [lldb] Fix windows path guessing for root paths Fix recognizing ":\" as a windows path. Differential Revision: https://reviews.llvm.org/D115104 --- lldb/source/Utility/FileSpec.cpp | 2 +- lldb/unittests/Utility/FileSpecTest.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp index 601edb8..24f8c2b 100644 --- a/lldb/source/Utility/FileSpec.cpp +++ b/lldb/source/Utility/FileSpec.cpp @@ -310,7 +310,7 @@ llvm::Optional FileSpec::GuessPathStyle(llvm::StringRef absolut return Style::posix; if (absolute_path.startswith(R"(\\)")) return Style::windows; - if (absolute_path.size() > 3 && llvm::isAlpha(absolute_path[0]) && + if (absolute_path.size() >= 3 && llvm::isAlpha(absolute_path[0]) && absolute_path.substr(1, 2) == R"(:\)") return Style::windows; return llvm::None; diff --git a/lldb/unittests/Utility/FileSpecTest.cpp b/lldb/unittests/Utility/FileSpecTest.cpp index 3dd3552..64b72be 100644 --- a/lldb/unittests/Utility/FileSpecTest.cpp +++ b/lldb/unittests/Utility/FileSpecTest.cpp @@ -198,8 +198,10 @@ TEST(FileSpecTest, GuessPathStyle) { FileSpec::GuessPathStyle(R"(C:\foo.txt)")); EXPECT_EQ(FileSpec::Style::windows, FileSpec::GuessPathStyle(R"(\\net\foo.txt)")); + EXPECT_EQ(FileSpec::Style::windows, FileSpec::GuessPathStyle(R"(Z:\)")); EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo.txt")); EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo/bar.txt")); + EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("Z:")); } TEST(FileSpecTest, GetPath) { -- 2.7.4