Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/json/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public JSONArray(JSONTokener x, JSONParserConfiguration jsonParserConfiguration)
if (nextChar == 0) {
// array is unclosed. No ']' found, instead EOF
throw x.syntaxError("Expected a ',' or ']'");
} else if (nextChar==',' && jsonParserConfiguration.isStrictMode()) {
Copy link
Owner

@stleary stleary Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add at least one test case to JSONArrayTest.java to provide coverage for the new code
For example, this tests both jsonobject and jsonarray, with and without strict mode. It also handles the 'TestWithStrictMode' gradle task where strict mode is always set.

    @Test
    public void foo() {
        String s = "{\"a\":[ ,4,null,8]}";
        JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration();
        if (jsonParserConfiguration.isStrictMode()) {
            // expect an error during strict mode testing
            assertThrows(JSONException.class, () -> { new JSONObject(s); });
        } else {
            new JSONObject(s);
        }
        assertThrows(JSONException.class, () -> { new JSONObject(s, new JSONParserConfiguration().withStrictMode(true)); });
        String s2 = "[,4,null,8]";
        if (jsonParserConfiguration.isStrictMode()) {
            // expect an error during strict mode testing
            assertThrows(JSONException.class, () -> { new JSONArray(s2); });
        } else {
            new JSONArray(s2);
        }
        assertThrows(JSONException.class, () -> { new JSONArray(s2, new JSONParserConfiguration().withStrictMode(true)); });
    }

throw x.syntaxError("Array content starts with a ','");
}
if (nextChar != ']') {
x.back();
Expand Down