#947 add new failing tests with JSONTokener having strict mode configuration

This commit is contained in:
Simulant 2025-01-15 21:38:46 +01:00
parent dde9d7eceb
commit 6631b80e8f
2 changed files with 18 additions and 0 deletions

View File

@ -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<Object> buildNestedArray(int maxDepth) {
if (maxDepth <= 0) {
return new ArrayList<>();

View File

@ -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
*