JSON-java
JSON-java copied to clipboard
DEL control character (0x007F) is not escaped
https://github.com/stleary/JSON-java/blame/master/src/main/java/org/json/JSONObject.java#L2080
System.out.println(java.lang.Character.isISOControl(0x007f));
System.out.println(new JSONObject("{\"a\":\"\u007f\"}").toString(0));
Thanks, this does look like a bug. Please feel free to post a PR.
adding an additional || java.lang.Character.isISOControl(c) to the if should be sufficient. The function was added in 1.5 so it should be available for all our supported platforms.
or better may be to just replace the first 2 check with that function, so the new if would look like:
if (Character.isISOControl(c) || (c >= '\u2000' && c < '\u2100')) {
- or copy the (optimized) implementation of
Character.isISOControl(int) - or use
Character.isISOControl((int) c)in order to save one method call
I would prefer the Character.isISOControl((int) c) call over the copy/paste so any future changes to the call would be available on a JVM update.
Closed due to lack of activity.