@@ -121,6 +121,10 @@ private void parseTokener(JSONTokener x, JSONParserConfiguration jsonParserConfi
121
121
122
122
throwErrorIfEoF (x );
123
123
124
+ if (strictMode && cursor == ']' ){
125
+ throw x .syntaxError (getInvalidCharErrorMsg (cursor ));
126
+ }
127
+
124
128
if (cursor == ']' ) {
125
129
break ;
126
130
}
@@ -135,7 +139,7 @@ private void parseTokener(JSONTokener x, JSONParserConfiguration jsonParserConfi
135
139
boolean isNotEoF = !x .end ();
136
140
137
141
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 ));
139
143
}
140
144
141
145
x .back ();
@@ -147,7 +151,7 @@ private void parseTokener(JSONTokener x, JSONParserConfiguration jsonParserConfi
147
151
boolean quoteIsNotNextToValidChar = x .getPreviousChar () != ',' && x .getPreviousChar () != '[' ;
148
152
149
153
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 ));
151
155
}
152
156
153
157
this .myArrayList .add (x .nextValue (jsonParserConfiguration ));
@@ -1954,6 +1958,7 @@ private void addAll(Object array, boolean wrap) throws JSONException {
1954
1958
private void addAll (Object array , boolean wrap , int recursionDepth ) {
1955
1959
addAll (array , wrap , recursionDepth , new JSONParserConfiguration ());
1956
1960
}
1961
+
1957
1962
/**
1958
1963
* Add an array's elements to the JSONArray.
1959
1964
*`
@@ -2000,7 +2005,6 @@ private void addAll(Object array, boolean wrap, int recursionDepth, JSONParserCo
2000
2005
"JSONArray initial value should be a string or collection or array." );
2001
2006
}
2002
2007
}
2003
-
2004
2008
/**
2005
2009
* Create a new JSONException in a common format for incorrect conversions.
2006
2010
* @param idx index of the item
@@ -2029,4 +2033,7 @@ private static JSONException wrongValueFormatException(
2029
2033
, cause );
2030
2034
}
2031
2035
2036
+ private static String getInvalidCharErrorMsg (char cursor ) {
2037
+ return String .format ("invalid character '%s' found after end of array" , cursor );
2038
+ }
2032
2039
}
0 commit comments