mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 19:35:31 -04:00
Don't skip past \0
when parsing JSON objects.
A better solution might be to use -1 instead 0 to represent EOF everywhere, which of course means changing `char` variables to `int`. The solution here is enough to solve the immediate problem, though. Fixes #758.
This commit is contained in:
parent
402db6ad84
commit
c8a9e15a57
@ -253,7 +253,11 @@ public class JSONObject {
|
|||||||
switch (x.nextClean()) {
|
switch (x.nextClean()) {
|
||||||
case ';':
|
case ';':
|
||||||
case ',':
|
case ',':
|
||||||
if (x.nextClean() == '}') {
|
c = x.nextClean();
|
||||||
|
if (c == 0) {
|
||||||
|
throw x.syntaxError("A JSONObject text must end with '}'");
|
||||||
|
}
|
||||||
|
if (c == '}') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
x.back();
|
x.back();
|
||||||
|
@ -2225,6 +2225,15 @@ public class JSONObjectTest {
|
|||||||
"Expected a ',' or '}' at 15 [character 16 line 1]",
|
"Expected a ',' or '}' at 15 [character 16 line 1]",
|
||||||
e.getMessage());
|
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 {
|
try {
|
||||||
// append to wrong key
|
// append to wrong key
|
||||||
String str = "{\"myKey\":true, \"myOtherKey\":false}";
|
String str = "{\"myKey\":true, \"myOtherKey\":false}";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user