Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed unnecessary escaping of '/' #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
5 changes: 1 addition & 4 deletions src/main/java/org/json/simple/JSONValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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')){
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/json/simple/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/");
Expand All @@ -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();
Expand Down