restore-jsonparserconfiguration: strict mode initial attempt. Still missing all JSONObject test cases and strict mode sanity check. Might be able to simplify implementation a bit more

This commit is contained in:
Sean Leary
2024-12-14 14:40:40 -06:00
parent 80b2672f77
commit 1f0729cadb
5 changed files with 679 additions and 6 deletions

View File

@@ -152,6 +152,10 @@ public class JSONObject {
*/
public static final Object NULL = new Null();
private JSONTokener jsonTokener;
private JSONParserConfiguration jsonParserConfiguration;
/**
* Construct an empty JSONObject.
*/
@@ -211,6 +215,15 @@ public class JSONObject {
*/
public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
this();
if (this.jsonParserConfiguration == null) {
this.jsonParserConfiguration = jsonParserConfiguration;
}
if (this.jsonTokener == null) {
this.jsonTokener = x;
this.jsonTokener.setJsonParserConfiguration(this.jsonParserConfiguration);
}
char c;
String key;
@@ -433,6 +446,10 @@ public class JSONObject {
*/
public JSONObject(String source) throws JSONException {
this(source, new JSONParserConfiguration());
if (this.jsonParserConfiguration.isStrictMode() &&
this.jsonTokener.nextClean() != 0) {
throw new JSONException("Unparsed characters found at end of input text");
}
}
/**