Skip to content

Commit

Permalink
fix(#887): allow null value strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
rikkarth committed Apr 23, 2024
1 parent ce13ebd commit 898dd5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/json/JSONTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ private Object parsedUnquotedText(char c, boolean strictMode) {
}

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;
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/java/org/json/junit/JSONParserConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public void givenInvalidString_testStrictModeTrue_shouldThrowJsonException() {
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]";
Expand Down

0 comments on commit 898dd5a

Please sign in to comment.