Merge pull request #759 from eamonnmcmanus/eofnull

JSON parsing should detect embedded `\0` values
This commit is contained in:
Sean Leary 2023-08-05 08:33:26 -05:00 committed by GitHub
commit 60662e2f83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -256,6 +256,9 @@ public class JSONObject {
if (x.nextClean() == '}') {
return;
}
if (x.end()) {
throw x.syntaxError("A JSONObject text must end with '}'");
}
x.back();
break;
case '}':

View File

@ -2225,6 +2225,15 @@ public class JSONObjectTest {
"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}";