Skip to content

Commit

Permalink
Merge pull request stleary#759 from eamonnmcmanus/eofnull
Browse files Browse the repository at this point in the history
JSON parsing should detect embedded `\0` values
  • Loading branch information
stleary authored and John J. Aylward committed Oct 17, 2023
1 parent a963115 commit ca48f2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/json/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ public JSONObject(JSONTokener x) throws JSONException {
if (x.nextClean() == '}') {
return;
}
if (x.end()) {
throw x.syntaxError("A JSONObject text must end with '}'");
}
x.back();
break;
case '}':
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/json/junit/JSONObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2198,6 +2198,15 @@ public void jsonObjectParsingErrors() {
"Expected a ',' or '}' at 15 [character 16 line 1]",
e.getMessage());
}
try {
// \0 after ,
String str = "{\"myKey\":true, \0\"myOtherKey\":false}";
assertNull("Expected an exception",new JSONObject(str));
} catch (JSONException e) {
assertEquals("Expecting an exception message",
"A JSONObject text must end with '}' at 15 [character 16 line 1]",
e.getMessage());
}
try {
// append to wrong key
String str = "{\"myKey\":true, \"myOtherKey\":false}";
Expand Down

0 comments on commit ca48f2d

Please sign in to comment.