Skip to content

Commit

Permalink
Merge pull request #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 Aug 5, 2023
2 parents 402db6a + 2a4bc34 commit 60662e2
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 @@ -2225,6 +2225,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 60662e2

Please # to comment.