fix escaping of strings in JSON values

Change-Id: If68c1c4606501dbd205e67d6a73f4086a8f0b793
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1271
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
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) {