File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ();
You can’t perform that action at this time.
0 commit comments