@@ -218,11 +218,16 @@ public void jsonObjectByNullBean() {
218
218
*/
219
219
@ Test
220
220
public void unquotedText () {
221
+ String str = "{key1:value1, key2:42, 1.2 : 3.4, -7e5 : something!}" ;
222
+
223
+ // Test should fail if default strictMode is true, pass if false
221
224
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration ();
222
225
if (jsonParserConfiguration .isStrictMode ()) {
223
- System .out .println ("Skipping JSONObjectTest unquotedText() when strictMode default is true" );
226
+ try {
227
+ JSONObject jsonObject = new JSONObject (str );
228
+ assertEquals ("Expected to throw exception due to invalid string" , true , false );
229
+ } catch (JSONException e ) { }
224
230
} else {
225
- String str = "{key1:value1, key2:42, 1.2 : 3.4, -7e5 : something!}" ;
226
231
JSONObject jsonObject = new JSONObject (str );
227
232
String textStr = jsonObject .toString ();
228
233
assertTrue ("expected key1" , textStr .contains ("\" key1\" " ));
@@ -1074,24 +1079,29 @@ public void jsonValidNumberValuesNeitherLongNorIEEE754Compatible() {
1074
1079
*/
1075
1080
@ Test
1076
1081
public void jsonInvalidNumberValues () {
1082
+ // Number-notations supported by Java and invalid as JSON
1083
+ String str =
1084
+ "{" +
1085
+ "\" hexNumber\" :-0x123," +
1086
+ "\" tooManyZeros\" :00," +
1087
+ "\" negativeInfinite\" :-Infinity," +
1088
+ "\" negativeNaN\" :-NaN," +
1089
+ "\" negativeFraction\" :-.01," +
1090
+ "\" tooManyZerosFraction\" :00.001," +
1091
+ "\" negativeHexFloat\" :-0x1.fffp1," +
1092
+ "\" hexFloat\" :0x1.0P-1074," +
1093
+ "\" floatIdentifier\" :0.1f," +
1094
+ "\" doubleIdentifier\" :0.1d" +
1095
+ "}" ;
1096
+
1097
+ // Test should fail if default strictMode is true, pass if false
1077
1098
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration ();
1078
1099
if (jsonParserConfiguration .isStrictMode ()) {
1079
- System .out .println ("Skipping JSONObjectTest jsonInvalidNumberValues() when strictMode default is true" );
1100
+ try {
1101
+ JSONObject jsonObject = new JSONObject (str );
1102
+ assertEquals ("Expected to throw exception due to invalid string" , true , false );
1103
+ } catch (JSONException e ) { }
1080
1104
} else {
1081
- // Number-notations supported by Java and invalid as JSON
1082
- String str =
1083
- "{" +
1084
- "\" hexNumber\" :-0x123," +
1085
- "\" tooManyZeros\" :00," +
1086
- "\" negativeInfinite\" :-Infinity," +
1087
- "\" negativeNaN\" :-NaN," +
1088
- "\" negativeFraction\" :-.01," +
1089
- "\" tooManyZerosFraction\" :00.001," +
1090
- "\" negativeHexFloat\" :-0x1.fffp1," +
1091
- "\" hexFloat\" :0x1.0P-1074," +
1092
- "\" floatIdentifier\" :0.1f," +
1093
- "\" doubleIdentifier\" :0.1d" +
1094
- "}" ;
1095
1105
JSONObject jsonObject = new JSONObject (str );
1096
1106
Object obj ;
1097
1107
obj = jsonObject .get ("hexNumber" );
@@ -2274,7 +2284,7 @@ public void jsonObjectParseIllegalEscapeAssertExceptionMessage(){
2274
2284
public void jsonObjectParsingErrors () {
2275
2285
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration ();
2276
2286
if (jsonParserConfiguration .isStrictMode ()) {
2277
- System .out .println ("Skipping JSONObjectTest jaonObjectParsingErrors () when strictMode default is true" );
2287
+ System .out .println ("Skipping JSONObjectTest jsonObjectParsingErrors () when strictMode default is true" );
2278
2288
} else {
2279
2289
try {
2280
2290
// does not start with '{'
0 commit comments