Add test cases for invalid input

This commit is contained in:
John J. Aylward
2022-01-26 12:19:53 -05:00
parent f1b0210b8a
commit 7a124d857d
8 changed files with 1732 additions and 4 deletions

View File

@@ -225,12 +225,19 @@ public class JSONObject {
throw x.syntaxError("A JSONObject text must begin with '{'");
}
for (;;) {
char prev = x.getPrevious();
c = x.nextClean();
switch (c) {
case 0:
throw x.syntaxError("A JSONObject text must end with '}'");
case '}':
return;
case '{':
case '[':
if(prev=='{') {
throw x.syntaxError("A JSON Object can not directly nest another JSON Object or JSON Array.");
}
// fall through
default:
x.back();
key = x.nextValue().toString();