diff --git a/src/test/java/org/json/junit/JSONArrayTest.java b/src/test/java/org/json/junit/JSONArrayTest.java index e6d7147..584e47c 100644 --- a/src/test/java/org/json/junit/JSONArrayTest.java +++ b/src/test/java/org/json/junit/JSONArrayTest.java @@ -8,6 +8,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -1509,6 +1510,14 @@ public class JSONArrayTest { new JSONArray(array); } + @Test + public void testStrictModeJSONTokener_expectException(){ + JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration().withStrictMode(); + JSONTokener tokener = new JSONTokener("[\"value\"]invalidCharacters", jsonParserConfiguration); + + assertThrows(JSONException.class, () -> { new JSONArray(tokener); }); + } + public static ArrayList buildNestedArray(int maxDepth) { if (maxDepth <= 0) { return new ArrayList<>(); diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 7f121f3..889113d 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -3853,6 +3853,15 @@ public class JSONObjectTest { assertEquals(j3.getString("hex6"), "0011"); } + + @Test + public void testStrictModeJSONTokener_expectException(){ + JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration().withStrictMode(); + JSONTokener tokener = new JSONTokener("{\"key\":\"value\"}invalidCharacters", jsonParserConfiguration); + + assertThrows(JSONException.class, () -> { new JSONObject(tokener); }); + } + /** * Method to build nested map of max maxDepth *