File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed
src/test/java/org/json/junit Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 88import static org .junit .Assert .assertFalse ;
99import static org .junit .Assert .assertNotNull ;
1010import static org .junit .Assert .assertNull ;
11+ import static org .junit .Assert .assertThrows ;
1112import static org .junit .Assert .assertTrue ;
1213import static org .junit .Assert .fail ;
1314
@@ -1509,6 +1510,14 @@ public void testRecursiveDepthArrayFor1001Levels() {
15091510 new JSONArray (array );
15101511 }
15111512
1513+ @ Test
1514+ public void testStrictModeJSONTokener_expectException (){
1515+ JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration ().withStrictMode ();
1516+ JSONTokener tokener = new JSONTokener ("[\" value\" ]invalidCharacters" , jsonParserConfiguration );
1517+
1518+ assertThrows (JSONException .class , () -> { new JSONArray (tokener ); });
1519+ }
1520+
15121521 public static ArrayList <Object > buildNestedArray (int maxDepth ) {
15131522 if (maxDepth <= 0 ) {
15141523 return new ArrayList <>();
Original file line number Diff line number Diff line change @@ -3853,6 +3853,15 @@ public void clarifyCurrentBehavior() {
38533853 assertEquals (j3 .getString ("hex6" ), "0011" );
38543854 }
38553855
3856+
3857+ @ Test
3858+ public void testStrictModeJSONTokener_expectException (){
3859+ JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration ().withStrictMode ();
3860+ JSONTokener tokener = new JSONTokener ("{\" key\" :\" value\" }invalidCharacters" , jsonParserConfiguration );
3861+
3862+ assertThrows (JSONException .class , () -> { new JSONObject (tokener ); });
3863+ }
3864+
38563865 /**
38573866 * Method to build nested map of max maxDepth
38583867 *
You can’t perform that action at this time.
0 commit comments