Skip to content

Commit

Permalink
fixes #372.
Browse files Browse the repository at this point in the history
Corrects behavior of unclosed arrays
  • Loading branch information
johnjaylward committed Oct 30, 2017
1 parent 057e0c7 commit ee9e706
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 @@ -107,7 +107,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 @@ -118,8 +124,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 ee9e706

Please sign in to comment.