Fixed JSONArray strict mode check for leading comma by eleumik · Pull Request #1008 · stleary/JSON-java
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)); });
}