Skip to content

Commit

Permalink
#947 add new failing tests with JSONTokener having strict mode config…
Browse files Browse the repository at this point in the history
…uration
  • Loading branch information
Simulant87 committed Jan 15, 2025
1 parent dde9d7e commit 6631b80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/test/java/org/json/junit/JSONArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;

Expand Down Expand Up @@ -1509,6 +1510,14 @@ public void testRecursiveDepthArrayFor1001Levels() {
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<>();
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/json/junit/JSONObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,15 @@ public void clarifyCurrentBehavior() {
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
*
Expand Down

0 comments on commit 6631b80

Please sign in to comment.