Generalize the logic to disallow nested objects and arrays as keys in objects.

Fixes #771.
This commit is contained in:
Éamonn McManus
2023-09-20 10:50:48 -07:00
parent 01727fd0ed
commit 661114c50d
3 changed files with 37 additions and 17 deletions

View File

@@ -402,12 +402,7 @@ public class JSONTokener {
*/
public Object nextValue() throws JSONException {
char c = this.nextClean();
String string;
switch (c) {
case '"':
case '\'':
return this.nextString(c);
case '{':
this.back();
try {
@@ -423,6 +418,21 @@ public class JSONTokener {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}
}
return nextSimpleValue(c);
}
Object nextSimpleValue(char c) {
String string;
switch (c) {
case '"':
case '\'':
return this.nextString(c);
case '{':
throw syntaxError("Nested object not expected here.");
case '[':
throw syntaxError("Nested array not expected here.");
}
/*
* Handle unquoted text. This could be the values true, false, or