fix(#887): allow null value strict mode

This commit is contained in:
rikkarth 2024-04-23 20:52:02 +01:00
parent ce13ebd5fe
commit 898dd5a39d
No known key found for this signature in database
GPG Key ID: 11E5F28B0AED6AC7
2 changed files with 8 additions and 1 deletions

View File

@ -527,7 +527,7 @@ public class JSONTokener {
}
private Object getValidNumberOrBooleanFromObject(Object value) {
if (value instanceof Number || value instanceof Boolean) {
if (value instanceof Number || value instanceof Boolean || value.equals(JSONObject.NULL)) {
return value;
}

View File

@ -75,6 +75,13 @@ public class JSONParserConfigurationTest {
assertEquals("Value is not surrounded by quotes: badString", je.getMessage());
}
@Test
public void allowNullInStrictMode() {
String expected = "[null]";
JSONArray jsonArray = new JSONArray(expected, new JSONParserConfiguration().withStrictMode(true));
assertEquals(expected, jsonArray.toString());
}
@Test
public void shouldHandleNumericArray() {
String expected = "[10]";