bneradt commented on code in PR #12463:
URL: https://github.com/apache/trafficserver/pull/12463#discussion_r2298402906


##########
plugins/xdebug/xdebug_transforms.cc:
##########
@@ -82,11 +84,107 @@ getPostBodyFullJson(TSHttpTxn txn)
   return output.str();
 }
 
+/** JSON-escape the given input stream. */
+static inline void
+write_json_escaped(TSIOBuffer output_buffer, const char *data, int64_t len, 
int64_t &written)
+{
+  for (int64_t i = 0; i < len; ++i) {
+    unsigned char c = static_cast<unsigned char>(data[i]);
+    switch (c) {
+    case '"': {
+      const char *s = "\\\"";
+      TSIOBufferWrite(output_buffer, s, 2);
+      written += 2;
+      break;
+    }
+    case '\\': {
+      const char *s = "\\\\";
+      TSIOBufferWrite(output_buffer, s, 2);
+      written += 2;
+      break;
+    }
+    case '\b': {
+      const char *s = "\\b";
+      TSIOBufferWrite(output_buffer, s, 2);
+      written += 2;
+      break;
+    }
+    case '\f': {
+      const char *s = "\\f";
+      TSIOBufferWrite(output_buffer, s, 2);
+      written += 2;
+      break;
+    }
+    case '\n': {
+      const char *s = "\\n";
+      TSIOBufferWrite(output_buffer, s, 2);
+      written += 2;
+      break;
+    }
+    case '\r': {
+      const char *s = "\\r";
+      TSIOBufferWrite(output_buffer, s, 2);
+      written += 2;
+      break;
+    }
+    case '\t': {
+      const char *s = "\\t";
+      TSIOBufferWrite(output_buffer, s, 2);
+      written += 2;
+      break;
+    }
+    default:
+      if (c < 0x20) {
+        char esc[6];
+        esc[0]                  = '\\';
+        esc[1]                  = 'u';
+        esc[2]                  = '0';
+        esc[3]                  = '0';
+        static const char hex[] = "0123456789abcdef";
+        esc[4]                  = hex[(c >> 4) & 0x0F];
+        esc[5]                  = hex[c & 0x0F];
+        TSIOBufferWrite(output_buffer, esc, 6);

Review Comment:
   Good point.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to