From b4ce28fd9a9d49ac492c1a134e0eb6507df2b45b Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Sat, 30 Jul 2011 02:13:45 -0500 Subject: [PATCH] Make JSON unicode encoding more thorough - don't assume anything outside ASCII should not be escaped --- src/main/java/org/dynmap/web/Json.java | 48 +++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/dynmap/web/Json.java b/src/main/java/org/dynmap/web/Json.java index 17c1d54f..ea0a7f84 100644 --- a/src/main/java/org/dynmap/web/Json.java +++ b/src/main/java/org/dynmap/web/Json.java @@ -15,13 +15,59 @@ public class Json { return sb.toString(); } + public static void escape(String s, StringBuilder s2) { + for(int i=0;i='\u0000' && ch<='\u001F') || (ch>='\u007F')){ + String ss=Integer.toHexString(ch); + s2.append("\\u"); + for(int k=0;k<4-ss.length();k++){ + s2.append('0'); + } + s2.append(ss.toUpperCase()); + } + else{ + s2.append(ch); + } + } + }//for + } + public static void appendJson(Object o, StringBuilder s) { if (o == null) { s.append("null"); } else if (o instanceof Boolean) { s.append(((Boolean) o) ? "true" : "false"); } else if (o instanceof String) { - s.append("\"" + JSONObject.escape((String)o) + "\""); + s.append("\""); + escape((String)o, s); + s.append("\""); } else if (o instanceof Integer || o instanceof Long || o instanceof Float || o instanceof Double) { s.append(o.toString()); } else if (o instanceof Map) {