[PATCH] D63462: [analyzer] JsonSupport: Escape escapes

Csaba Dabis via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 17 15:59:50 PDT 2019


Charusso created this revision.
Charusso added a reviewer: NoQ.
Charusso added a project: clang.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.

-


Repository:
  rC Clang

https://reviews.llvm.org/D63462

Files:
  clang/include/clang/Basic/JsonSupport.h


Index: clang/include/clang/Basic/JsonSupport.h
===================================================================
--- clang/include/clang/Basic/JsonSupport.h
+++ clang/include/clang/Basic/JsonSupport.h
@@ -31,7 +31,26 @@
   std::string Str = RawSR.trim().str();
   size_t Pos = 0;
 
+  // Escape backslashes.
+  while (true) {
+    Pos = Str.find('\\', Pos);
+    if (Pos == std::string::npos)
+      break;
+
+    // Prevent bad conversions.
+    size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
+
+    // See whether the current backslash is not escaped.
+    if (TempPos != Str.find("\\\\", Pos)) {
+      Str.insert(Pos, "\\");
+      ++Pos; // As we insert the backslash move plus one.
+    }
+
+    ++Pos;
+  }
+
   // Escape double quotes.
+  Pos = 0;
   while (true) {
     Pos = Str.find('\"', Pos);
     if (Pos == std::string::npos)
@@ -40,8 +59,8 @@
     // Prevent bad conversions.
     size_t TempPos = (Pos != 0) ? Pos - 1 : 0;
 
-    // See whether the current double quote is escaped.
-    if (TempPos != Str.find("\\\"", TempPos)) {
+    // See whether the current double quote is not escaped.
+    if (TempPos != Str.find("\\\"", Pos)) {
       Str.insert(Pos, "\\");
       ++Pos; // As we insert the escape-character move plus one.
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63462.205210.patch
Type: text/x-patch
Size: 1255 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190617/9f82da92/attachment.bin>


More information about the cfe-commits mailing list