@@ -2193,6 +2193,60 @@ public void jsonObjectParseControlCharacters(){
2193
2193
}
2194
2194
}
2195
2195
2196
+ @ Test
2197
+ public void jsonObjectParseControlCharacterEOFAssertExceptionMessage (){
2198
+ char c = '\0' ;
2199
+ final String source = "{\" key\" :\" " + c + "\" }" ;
2200
+ try {
2201
+ JSONObject jo = new JSONObject (source );
2202
+ fail ("JSONException should be thrown" );
2203
+ } catch (JSONException ex ) {
2204
+ assertEquals ("Unterminated string. " + "Character with int code 0" +
2205
+ " is not allowed within a quoted string. at 8 [character 9 line 1]" , ex .getMessage ());
2206
+ }
2207
+ }
2208
+
2209
+ @ Test
2210
+ public void jsonObjectParseControlCharacterNewLineAssertExceptionMessage (){
2211
+ char [] chars = {'\n' , '\r' };
2212
+ for ( char c : chars ) {
2213
+ final String source = "{\" key\" :\" " + c + "\" }" ;
2214
+ try {
2215
+ JSONObject jo = new JSONObject (source );
2216
+ fail ("JSONException should be thrown" );
2217
+ } catch (JSONException ex ) {
2218
+ assertEquals ("Unterminated string. " + "Character with int code " + (int ) c +
2219
+ " is not allowed within a quoted string. at 9 [character 0 line 2]" , ex .getMessage ());
2220
+ }
2221
+ }
2222
+ }
2223
+
2224
+ @ Test
2225
+ public void jsonObjectParseUTF8EncodingAssertExceptionMessage (){
2226
+ String c = "\\ u123x" ;
2227
+ final String source = "{\" key\" :\" " + c + "\" }" ;
2228
+ try {
2229
+ JSONObject jo = new JSONObject (source );
2230
+ fail ("JSONException should be thrown" );
2231
+ } catch (JSONException ex ) {
2232
+ assertEquals ("Illegal escape. \\ u must be followed by a 4 digit hexadecimal number. " +
2233
+ "\\ 123x is not valid. at 14 [character 15 line 1]" , ex .getMessage ());
2234
+ }
2235
+ }
2236
+
2237
+ @ Test
2238
+ public void jsonObjectParseIllegalEscapeAssertExceptionMessage (){
2239
+ String c = "\\ x" ;
2240
+ final String source = "{\" key\" :\" " + c + "\" }" ;
2241
+ try {
2242
+ JSONObject jo = new JSONObject (source );
2243
+ fail ("JSONException should be thrown" );
2244
+ } catch (JSONException ex ) {
2245
+ assertEquals ("Illegal escape. Escape sequence " + c + " is not valid." +
2246
+ " at 10 [character 11 line 1]" , ex .getMessage ());
2247
+ }
2248
+ }
2249
+
2196
2250
/**
2197
2251
* Explore how JSONObject handles parsing errors.
2198
2252
*/
0 commit comments