mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 11:25:30 -04:00
#947 add new failing tests with JSONTokener having strict mode configuration
This commit is contained in:
parent
dde9d7eceb
commit
6631b80e8f
@ -8,6 +8,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@ -1509,6 +1510,14 @@ public class JSONArrayTest {
|
|||||||
new JSONArray(array);
|
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) {
|
public static ArrayList<Object> buildNestedArray(int maxDepth) {
|
||||||
if (maxDepth <= 0) {
|
if (maxDepth <= 0) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
@ -3853,6 +3853,15 @@ public class JSONObjectTest {
|
|||||||
assertEquals(j3.getString("hex6"), "0011");
|
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
|
* Method to build nested map of max maxDepth
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user