restore-jsonparserconfiguration: add jsonobject strict tests. Detect semicolon instead of colon separator in object

This commit is contained in:
Sean Leary
2024-12-15 10:38:54 -06:00
parent 1f0729cadb
commit 09536cd6c8
3 changed files with 3975 additions and 38 deletions

View File

@@ -268,8 +268,14 @@ public class JSONObject {
switch (x.nextClean()) {
case ';':
if (jsonParserConfiguration.isStrictMode()) {
throw x.syntaxError("Invalid character ';' found in object in strict mode");
}
case ',':
if (x.nextClean() == '}') {
if (jsonParserConfiguration.isStrictMode()) {
throw x.syntaxError("Expected another object element");
}
return;
}
if (x.end()) {
@@ -468,6 +474,13 @@ public class JSONObject {
*/
public JSONObject(String source, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
this(new JSONTokener(source), jsonParserConfiguration);
if (this.jsonParserConfiguration.isStrictMode()) {
char c = jsonTokener.nextClean();
if (c != 0) {
throw jsonTokener.syntaxError(String.format("invalid character '%s' found after end of array", c));
}
}
}
/**