Yingyi Bu has submitted this change and it was merged.

Change subject: fix escaping of strings in JSON values
......................................................................


fix escaping of strings in JSON values

Change-Id: If68c1c4606501dbd205e67d6a73f4086a8f0b793
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1271
Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyin...@gmail.com>
Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
---
M 
asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/JSONUtil.java
1 file changed, 6 insertions(+), 5 deletions(-)

Approvals:
  Yingyi Bu: Looks good to me, approved
  Jenkins: Verified; No violations found; Verified



diff --git 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/JSONUtil.java
 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/JSONUtil.java
index fd89c5e..0cbf1b9 100644
--- 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/JSONUtil.java
+++ 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/utils/JSONUtil.java
@@ -49,7 +49,7 @@
         } else if (o instanceof JSONArray) {
             return append(sb, (JSONArray) o, indent);
         } else if (o instanceof String) {
-            return quote(sb, (String) o);
+            return quoteAndEscape(sb, (String) o);
         } else if (JSONObject.NULL.equals(o) || o instanceof Number || o 
instanceof Boolean) {
             return sb.append(String.valueOf(o));
         }
@@ -102,10 +102,11 @@
     }
 
     public static String quoteAndEscape(String str) {
-        StringBuilder sb = new StringBuilder();
-        sb.append('"');
-        escape(sb, str);
-        return sb.append('"').toString();
+        return quoteAndEscape(new StringBuilder(), str).toString();
+    }
+
+    private static StringBuilder quoteAndEscape(StringBuilder sb, String str) {
+        return escape(sb.append('"'), str).append('"');
     }
 
     public static String escape(String str) {

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1271
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If68c1c4606501dbd205e67d6a73f4086a8f0b793
Gerrit-PatchSet: 2
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <ti...@apache.org>
Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Yingyi Bu <buyin...@gmail.com>

Reply via email to