@@ -121,6 +121,10 @@ private void parseTokener(JSONTokener x, JSONParserConfiguration jsonParserConfi
121121
122122 throwErrorIfEoF (x );
123123
124+ if (strictMode && cursor == ']' ){
125+ throw x .syntaxError (getInvalidCharErrorMsg (cursor ));
126+ }
127+
124128 if (cursor == ']' ) {
125129 break ;
126130 }
@@ -135,7 +139,7 @@ private void parseTokener(JSONTokener x, JSONParserConfiguration jsonParserConfi
135139 boolean isNotEoF = !x .end ();
136140
137141 if (isNotEoF && x .getArrayLevel () == 0 ) {
138- throw x .syntaxError (String . format ( "invalid character '%s' found after end of array" , cursor ));
142+ throw x .syntaxError (getInvalidCharErrorMsg ( cursor ));
139143 }
140144
141145 x .back ();
@@ -147,7 +151,7 @@ private void parseTokener(JSONTokener x, JSONParserConfiguration jsonParserConfi
147151 boolean quoteIsNotNextToValidChar = x .getPreviousChar () != ',' && x .getPreviousChar () != '[' ;
148152
149153 if (strictMode && currentCharIsQuote && quoteIsNotNextToValidChar ) {
150- throw x .syntaxError (String . format ( "invalid character '%s' found after end of array" , cursor ));
154+ throw x .syntaxError (getInvalidCharErrorMsg ( cursor ));
151155 }
152156
153157 this .myArrayList .add (x .nextValue (jsonParserConfiguration ));
@@ -1954,6 +1958,7 @@ private void addAll(Object array, boolean wrap) throws JSONException {
19541958 private void addAll (Object array , boolean wrap , int recursionDepth ) {
19551959 addAll (array , wrap , recursionDepth , new JSONParserConfiguration ());
19561960 }
1961+
19571962 /**
19581963 * Add an array's elements to the JSONArray.
19591964 *`
@@ -2000,7 +2005,6 @@ private void addAll(Object array, boolean wrap, int recursionDepth, JSONParserCo
20002005 "JSONArray initial value should be a string or collection or array." );
20012006 }
20022007 }
2003-
20042008 /**
20052009 * Create a new JSONException in a common format for incorrect conversions.
20062010 * @param idx index of the item
@@ -2029,4 +2033,7 @@ private static JSONException wrongValueFormatException(
20292033 , cause );
20302034 }
20312035
2036+ private static String getInvalidCharErrorMsg (char cursor ) {
2037+ return String .format ("invalid character '%s' found after end of array" , cursor );
2038+ }
20322039}
0 commit comments