From 0339d4498366a6764e5d0ccaf6f0ed804451011e Mon Sep 17 00:00:00 2001 From: zerucus Date: Mon, 19 Dec 2016 22:27:27 +0100 Subject: [PATCH] remove unnecessary escaping of '/' --- .gitignore | 1 + src/main/java/org/json/simple/JSONValue.java | 5 +---- src/test/java/org/json/simple/Test.java | 10 +++++----- 3 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a6f89c2d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ \ No newline at end of file diff --git a/src/main/java/org/json/simple/JSONValue.java b/src/main/java/org/json/simple/JSONValue.java index 2fddb217..2b6939c6 100644 --- a/src/main/java/org/json/simple/JSONValue.java +++ b/src/main/java/org/json/simple/JSONValue.java @@ -251,7 +251,7 @@ public static String toJSONString(Object value){ } /** - * Escape quotes, \, /, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F). + * Escape quotes, \, \r, \n, \b, \f, \t and other control characters (U+0000 through U+001F). * @param s * @return */ @@ -293,9 +293,6 @@ static void escape(String s, StringBuffer sb) { case '\t': sb.append("\\t"); break; - case '/': - sb.append("\\/"); - break; default: //Reference: http://www.unicode.org/versions/Unicode5.1.0/ if((ch>='\u0000' && ch<='\u001F') || (ch>='\u007F' && ch<='\u009F') || (ch>='\u2000' && ch<='\u20FF')){ diff --git a/src/test/java/org/json/simple/Test.java b/src/test/java/org/json/simple/Test.java index dc5ce033..7e6c910e 100644 --- a/src/test/java/org/json/simple/Test.java +++ b/src/test/java/org/json/simple/Test.java @@ -306,21 +306,21 @@ public void testEncode() throws Exception{ System.out.println("======array1=========="); System.out.println(array1); System.out.println(); - assertEquals("[\"abc\\u0010a\\/\",123,222.123,true]",array1.toString()); + assertEquals("[\"abc\\u0010a/\",123,222.123,true]",array1.toString()); JSONObject obj1=new JSONObject(); obj1.put("array1",array1); System.out.println("======obj1 with array1==========="); System.out.println(obj1); System.out.println(); - assertEquals("{\"array1\":[\"abc\\u0010a\\/\",123,222.123,true]}",obj1.toString()); + assertEquals("{\"array1\":[\"abc\\u0010a/\",123,222.123,true]}",obj1.toString()); obj1.remove("array1"); array1.add(obj1); System.out.println("======array1 with obj1========"); System.out.println(array1); System.out.println(); - assertEquals("[\"abc\\u0010a\\/\",123,222.123,true,{}]",array1.toString()); + assertEquals("[\"abc\\u0010a/\",123,222.123,true,{}]",array1.toString()); List list = new ArrayList(); list.add("abc\u0010a/"); @@ -331,14 +331,14 @@ public void testEncode() throws Exception{ System.out.println("======list=========="); System.out.println(JSONArray.toJSONString(list)); System.out.println(); - assertEquals("[\"abc\\u0010a\\/\",123,222.123,true,null]",JSONArray.toJSONString(list)); + assertEquals("[\"abc\\u0010a/\",123,222.123,true,null]",JSONArray.toJSONString(list)); Map map = new HashMap(); map.put("array1",list); System.out.println("======map with list==========="); System.out.println(map); System.out.println(); - assertEquals("{\"array1\":[\"abc\\u0010a\\/\",123,222.123,true,null]}",JSONObject.toJSONString(map)); + assertEquals("{\"array1\":[\"abc\\u0010a/\",123,222.123,true,null]}",JSONObject.toJSONString(map)); Map m1 = new LinkedHashMap(); Map m2 = new LinkedHashMap();