Skip to content

Commit 6631b80

Browse files
committed
#947 add new failing tests with JSONTokener having strict mode configuration
1 parent dde9d7e commit 6631b80

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/test/java/org/json/junit/JSONArrayTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.junit.Assert.assertFalse;
99
import static org.junit.Assert.assertNotNull;
1010
import static org.junit.Assert.assertNull;
11+
import static org.junit.Assert.assertThrows;
1112
import static org.junit.Assert.assertTrue;
1213
import 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<>();

src/test/java/org/json/junit/JSONObjectTest.java

+9
Original file line numberDiff line numberDiff 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
*

0 commit comments

Comments
 (0)