1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00
Corrects behavior of unclosed arrays
This commit is contained in:
John J. Aylward 2017-10-30 08:10:06 -04:00
parent cdf3cf7f81
commit ed8745cd63

View file

@ -107,7 +107,13 @@ public class JSONArray implements Iterable<Object> {
if (x.nextClean() != '[') { if (x.nextClean() != '[') {
throw x.syntaxError("A JSONArray text must start with '['"); 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(); x.back();
for (;;) { for (;;) {
if (x.nextClean() == ',') { if (x.nextClean() == ',') {
@ -118,8 +124,16 @@ public class JSONArray implements Iterable<Object> {
this.myArrayList.add(x.nextValue()); this.myArrayList.add(x.nextValue());
} }
switch (x.nextClean()) { switch (x.nextClean()) {
case 0:
// array is unclosed. No ']' found, instead EOF
throw new JSONException(x.syntaxError("Expected a ',' or ']'"));
case ',': 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; return;
} }
x.back(); x.back();