Skip to content

Commit ed8745c

Browse files
committed
fixes #372.
Corrects behavior of unclosed arrays
1 parent cdf3cf7 commit ed8745c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

JSONArray.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ public JSONArray(JSONTokener x) throws JSONException {
107107
if (x.nextClean() != '[') {
108108
throw x.syntaxError("A JSONArray text must start with '['");
109109
}
110-
if (x.nextClean() != ']') {
110+
111+
char nextChar = x.nextClean();
112+
if (nextChar == 0) {
113+
// array is unclosed. No ']' found, instead EOF
114+
throw new JSONException(x.syntaxError("Expected a ',' or ']'"));
115+
}
116+
if (nextChar != ']') {
111117
x.back();
112118
for (;;) {
113119
if (x.nextClean() == ',') {
@@ -118,8 +124,16 @@ public JSONArray(JSONTokener x) throws JSONException {
118124
this.myArrayList.add(x.nextValue());
119125
}
120126
switch (x.nextClean()) {
127+
case 0:
128+
// array is unclosed. No ']' found, instead EOF
129+
throw new JSONException(x.syntaxError("Expected a ',' or ']'"));
121130
case ',':
122-
if (x.nextClean() == ']') {
131+
nextChar = x.nextClean();
132+
if (nextChar == 0) {
133+
// array is unclosed. No ']' found, instead EOF
134+
throw new JSONException(x.syntaxError("Expected a ',' or ']'"));
135+
}
136+
if (nextChar == ']') {
123137
return;
124138
}
125139
x.back();

0 commit comments

Comments
 (0)