@@ -3997,6 +3997,45 @@ public void testStrictModeJSONTokener_expectException(){
39973997 assertThrows (JSONException .class , () -> { new JSONObject (tokener ); });
39983998 }
39993999
4000+ @ Test
4001+ public void test_strictModeWithMisCasedBooleanOrNullValue (){
4002+ JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration ().withStrictMode ();
4003+
4004+ try {
4005+ JSONObject j1 = new JSONObject ("{\" a\" :True}" , jsonParserConfiguration );
4006+ fail ("Expected an exception" );
4007+ } catch (JSONException e ) { }
4008+ try {
4009+ JSONObject j2 = new JSONObject ("{\" a\" :TRUE}" , jsonParserConfiguration );
4010+ fail ("Expected an exception" );
4011+ } catch (JSONException e ) { }
4012+ try {
4013+ JSONObject j2 = new JSONObject ("{\" a\" :nUlL}" , jsonParserConfiguration );
4014+ fail ("Expected an exception" );
4015+ } catch (JSONException e ) { }
4016+ }
4017+
4018+ @ Test
4019+ public void test_strictModeWithInappropriateKey (){
4020+ JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration ().withStrictMode ();
4021+
4022+ // Parsing the following objects should fail
4023+ try {
4024+ JSONObject j3 = new JSONObject ("{true : 3}" , jsonParserConfiguration );
4025+ fail ("Expected an exception" );
4026+ } catch (JSONException e ) { }
4027+ try {
4028+ JSONObject j4 = new JSONObject ("{TRUE : 3}" , jsonParserConfiguration );
4029+ fail ("Expected an exception" );
4030+ } catch (JSONException e ) { }
4031+ try {
4032+ JSONObject j5 = new JSONObject ("{1 : 3}" , jsonParserConfiguration );
4033+ fail ("Expected an exception" );
4034+ } catch (JSONException e ) { }
4035+
4036+ }
4037+
4038+
40004039 /**
40014040 * Method to build nested map of max maxDepth
40024041 *
0 commit comments