[PATCH] D53016: [clangd] Mark colon as a safe character when percent-encoding.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 9 01:25:03 PDT 2018


kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric, ilya-biryukov.

Also change output of percent-encoding to use upper-case letters.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53016

Files:
  clangd/URI.cpp
  unittests/clangd/URITests.cpp


Index: unittests/clangd/URITests.cpp
===================================================================
--- unittests/clangd/URITests.cpp
+++ unittests/clangd/URITests.cpp
@@ -44,8 +44,9 @@
 
 TEST(PercentEncodingTest, Encode) {
   EXPECT_EQ(URI("x", /*Authority=*/"", "a/b/c").toString(), "x:a/b/c");
-  EXPECT_EQ(URI("x", /*Authority=*/"", "a!b;c~").toString(), "x:a%21b%3bc~");
+  EXPECT_EQ(URI("x", /*Authority=*/"", "a!b;c~").toString(), "x:a%21b%3Bc~");
   EXPECT_EQ(URI("x", /*Authority=*/"", "a123b").toString(), "x:a123b");
+  EXPECT_EQ(URI("x", /*Authority=*/"", "a:b;c").toString(), "x:a:b%3Bc");
 }
 
 TEST(PercentEncodingTest, Decode) {
@@ -56,6 +57,7 @@
   EXPECT_EQ(parseOrDie("s%2b://%3a/%3").body(), "/%3");
 
   EXPECT_EQ(parseOrDie("x:a%21b%3ac~").body(), "a!b:c~");
+  EXPECT_EQ(parseOrDie("x:a:b%3bc").body(), "a:b;c");
 }
 
 std::string resolveOrDie(const URI &U, llvm::StringRef HintPath = "") {
@@ -67,10 +69,10 @@
 
 TEST(URITest, Create) {
 #ifdef _WIN32
-  EXPECT_THAT(createOrDie("c:\\x\\y\\z"), "file:///c%3a/x/y/z");
+  EXPECT_THAT(createOrDie("c:\\x\\y\\z"), "file:///c:/x/y/z");
 #else
   EXPECT_THAT(createOrDie("/x/y/z"), "file:///x/y/z");
-  EXPECT_THAT(createOrDie("/(x)/y/\\ z"), "file:///%28x%29/y/%5c%20z");
+  EXPECT_THAT(createOrDie("/(x)/y/\\ z"), "file:///%28x%29/y/%5C%20z");
 #endif
 }
 
@@ -138,6 +140,7 @@
 TEST(URITest, Resolve) {
 #ifdef _WIN32
   EXPECT_THAT(resolveOrDie(parseOrDie("file:///c%3a/x/y/z")), "c:\\x\\y\\z");
+  EXPECT_THAT(resolveOrDie(parseOrDie("file:///c:/x/y/z")), "c:\\x\\y\\z");
 #else
   EXPECT_EQ(resolveOrDie(parseOrDie("file:/a/b/c")), "/a/b/c");
   EXPECT_EQ(resolveOrDie(parseOrDie("file://auth/a/b/c")), "/a/b/c");
Index: clangd/URI.cpp
===================================================================
--- clangd/URI.cpp
+++ clangd/URI.cpp
@@ -91,6 +91,7 @@
   case '.':
   case '~':
   case '/': // '/' is only reserved when parsing.
+  case ':':
     return false;
   }
   return true;
@@ -105,7 +106,7 @@
   llvm::raw_string_ostream OS(Result);
   for (unsigned char C : Content)
     if (shouldEscape(C))
-      OS << '%' << llvm::format_hex_no_prefix(C, 2);
+      OS << '%' << llvm::format_hex_no_prefix(C, 2, /*Upper = */true);
     else
       OS << C;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53016.168758.patch
Type: text/x-patch
Size: 2245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181009/4f5464b8/attachment-0001.bin>


More information about the cfe-commits mailing list