[clang-tools-extra] [Clangd] Sanitize path before recording into IncludeStructure during buildPreamble (PR #70798)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 8 09:01:04 PST 2023


https://github.com/Maddobun updated https://github.com/llvm/llvm-project/pull/70798

>From 0572afa42e4e6ca1d1de0e9df045828552cb4480 Mon Sep 17 00:00:00 2001
From: Leo Zhu <yifu.zhu at microchip.com>
Date: Wed, 8 Nov 2023 11:10:13 -0500
Subject: [PATCH] Convert URI to uppercase drive letter during parsing

---
 clang-tools-extra/clangd/URI.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clangd/URI.cpp b/clang-tools-extra/clangd/URI.cpp
index ca65df329aeebf3..4bd4b6db9f51db4 100644
--- a/clang-tools-extra/clangd/URI.cpp
+++ b/clang-tools-extra/clangd/URI.cpp
@@ -165,8 +165,7 @@ std::string URI::toString() const {
     return Result;
   // If authority if empty, we only print body if it starts with "/"; otherwise,
   // the URI is invalid.
-  if (!Authority.empty() || llvm::StringRef(Body).startswith("/"))
-  {
+  if (!Authority.empty() || llvm::StringRef(Body).startswith("/")) {
     Result.append("//");
     percentEncode(Authority, Result);
   }
@@ -192,6 +191,10 @@ llvm::Expected<URI> URI::parse(llvm::StringRef OrigUri) {
     Uri = Uri.substr(Pos);
   }
   U.Body = percentDecode(Uri);
+  if (clang::clangd::isWindowsPath(U.Body)) {
+    Pos = U.Body.find(":");
+    U.Body.at(Pos - 1) = std::toupper(U.Body.at(Pos - 1));
+  }
   return U;
 }
 



More information about the cfe-commits mailing list