Skip to content

Commit 09536cd

Browse files
Sean LearySean Leary
authored andcommitted
restore-jsonparserconfiguration: add jsonobject strict tests. Detect semicolon instead of colon separator in object
1 parent 1f0729c commit 09536cd

File tree

3 files changed

+3975
-38
lines changed

3 files changed

+3975
-38
lines changed

src/main/java/org/json/JSONObject.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,14 @@ public JSONObject(JSONTokener x, JSONParserConfiguration jsonParserConfiguration
268268

269269
switch (x.nextClean()) {
270270
case ';':
271+
if (jsonParserConfiguration.isStrictMode()) {
272+
throw x.syntaxError("Invalid character ';' found in object in strict mode");
273+
}
271274
case ',':
272275
if (x.nextClean() == '}') {
276+
if (jsonParserConfiguration.isStrictMode()) {
277+
throw x.syntaxError("Expected another object element");
278+
}
273279
return;
274280
}
275281
if (x.end()) {
@@ -468,6 +474,13 @@ public JSONObject(String source) throws JSONException {
468474
*/
469475
public JSONObject(String source, JSONParserConfiguration jsonParserConfiguration) throws JSONException {
470476
this(new JSONTokener(source), jsonParserConfiguration);
477+
if (this.jsonParserConfiguration.isStrictMode()) {
478+
char c = jsonTokener.nextClean();
479+
if (c != 0) {
480+
throw jsonTokener.syntaxError(String.format("invalid character '%s' found after end of array", c));
481+
482+
}
483+
}
471484
}
472485

473486
/**

0 commit comments

Comments
 (0)