Skip to content

Commit

Permalink
fixes stleary#372.
Browse files Browse the repository at this point in the history
Corrects behavior of unclosed arrays
  • Loading branch information
johnjaylward authored and YellowfinBI committed Dec 8, 2022
1 parent 0323ff4 commit 9313524
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ public JSONArray(JSONTokener x) throws JSONException {
if (x.nextClean() != '[') {
throw x.syntaxError("A JSONArray text must start with '['");
}
if (x.nextClean() != ']') {

char nextChar = x.nextClean();
if (nextChar == 0) {
// array is unclosed. No ']' found, instead EOF
throw new JSONException(x.syntaxError("Expected a ',' or ']'"));
}
if (nextChar != ']') {
x.back();
for (;;) {
if (x.nextClean() == ',') {
Expand All @@ -115,8 +121,16 @@ public JSONArray(JSONTokener x) throws JSONException {
this.myArrayList.add(x.nextValue());
}
switch (x.nextClean()) {
case 0:
// array is unclosed. No ']' found, instead EOF
throw new JSONException(x.syntaxError("Expected a ',' or ']'"));
case ',':
if (x.nextClean() == ']') {
nextChar = x.nextClean();
if (nextChar == 0) {
// array is unclosed. No ']' found, instead EOF
throw new JSONException(x.syntaxError("Expected a ',' or ']'"));
}
if (nextChar == ']') {
return;
}
x.back();
Expand Down

0 comments on commit 9313524

Please sign in to comment.