Fixes corner case where strict mode isn't working when JSONTokener's next() and back() are called first

This commit is contained in:
XIAYM-gh
2026-09-02 20:31:40 +08:00
parent 4f859fdf3b
commit bcbbc89568
5 changed files with 81 additions and 7 deletions
+11 -2
View File
@@ -120,6 +120,15 @@ public class JSONTokener {
this.jsonParserConfiguration = jsonParserConfiguration;
}
/**
* Returns whether the tokener is currently positioned at the beginning,
*
* @return true if the current input position is the beginning
*/
public boolean isAtStart() {
return this.index == 0;
}
/**
* Back up one character. This provides a sort of lookahead capability,
* so that you can test for a digit or letter before attempting to parse
@@ -458,14 +467,14 @@ public class JSONTokener {
case '{':
this.back();
try {
return new JSONObject(this, jsonParserConfiguration);
return new JSONObject(this, jsonParserConfiguration, false);
} catch (StackOverflowError e) {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}
case '[':
this.back();
try {
return new JSONArray(this, jsonParserConfiguration);
return new JSONArray(this, jsonParserConfiguration, false);
} catch (StackOverflowError e) {
throw new JSONException("JSON Array or Object depth too large to process.", e);
}