Skip to content

Commit 898dd5a

Browse files
committed
fix(#887): allow null value strict mode
1 parent ce13ebd commit 898dd5a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/main/java/org/json/JSONTokener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private Object parsedUnquotedText(char c, boolean strictMode) {
527527
}
528528

529529
private Object getValidNumberOrBooleanFromObject(Object value) {
530-
if (value instanceof Number || value instanceof Boolean) {
530+
if (value instanceof Number || value instanceof Boolean || value.equals(JSONObject.NULL)) {
531531
return value;
532532
}
533533

src/test/java/org/json/junit/JSONParserConfigurationTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public void givenInvalidString_testStrictModeTrue_shouldThrowJsonException() {
7575
assertEquals("Value is not surrounded by quotes: badString", je.getMessage());
7676
}
7777

78+
@Test
79+
public void allowNullInStrictMode() {
80+
String expected = "[null]";
81+
JSONArray jsonArray = new JSONArray(expected, new JSONParserConfiguration().withStrictMode(true));
82+
assertEquals(expected, jsonArray.toString());
83+
}
84+
7885
@Test
7986
public void shouldHandleNumericArray() {
8087
String expected = "[10]";

0 commit comments

Comments
 (0)