FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #759 from eamonnmcmanus/eofnull · michael-ameri/JSON-java@60662e2 · GitHub

Commit 60662e2

Browse files
authored
Merge pull request stleary#759 from eamonnmcmanus/eofnull
JSON parsing should detect embedded `\0` values
2 parents 402db6a + 2a4bc34 commit 60662e2

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/main/java/org/json/JSONObject.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ public JSONObject(JSONTokener x) throws JSONException {
256256
if (x.nextClean() == '}') {
257257
return;
258258
}
259+
if (x.end()) {
260+
throw x.syntaxError("A JSONObject text must end with '}'");
261+
}
259262
x.back();
260263
break;
261264
case '}':

‎src/test/java/org/json/junit/JSONObjectTest.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,15 @@ public void jsonObjectParsingErrors() {
22252225
"Expected a ',' or '}' at 15 [character 16 line 1]",
22262226
e.getMessage());
22272227
}
2228+
try {
2229+
// \0 after ,
2230+
String str = "{\"myKey\":true, \0\"myOtherKey\":false}";
2231+
assertNull("Expected an exception",new JSONObject(str));
2232+
} catch (JSONException e) {
2233+
assertEquals("Expecting an exception message",
2234+
"A JSONObject text must end with '}' at 15 [character 16 line 1]",
2235+
e.getMessage());
2236+
}
22282237
try {
22292238
// append to wrong key
22302239
String str = "{\"myKey\":true, \"myOtherKey\":false}";

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL