Skip to content

Commit c91b728

Browse files
committed
oops forgot null
1 parent fdaeb48 commit c91b728

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -513,18 +513,19 @@ Object nextSimpleValue(char c) {
513513
Object obj = JSONObject.stringToValue(string);
514514
// if obj is a boolean, look at string
515515
if (jsonParserConfiguration != null &&
516-
jsonParserConfiguration.isStrictMode() && obj instanceof Boolean) {
517-
if (!"true".equals(string) && !"false".equals(string)) {
516+
jsonParserConfiguration.isStrictMode()) {
517+
if (obj instanceof Boolean && !"true".equals(string) && !"false".equals(string)) {
518+
// Strict mode only allows lowercase true or false
518519
throw this.syntaxError(String.format("Strict mode error: Value '%s' is not lowercase boolean", obj));
519520
}
520-
}
521-
522-
523-
// Strict mode only allows strings with explicit double quotes
524-
if (jsonParserConfiguration != null &&
525-
jsonParserConfiguration.isStrictMode() &&
526-
obj instanceof String) {
527-
throw this.syntaxError(String.format("Strict mode error: Value '%s' is not surrounded by quotes", obj));
521+
else if (obj == JSONObject.NULL && !"null".equals(string)) {
522+
// Strint mode only allows lowercase null
523+
throw this.syntaxError(String.format("Strict mode error: Value '%s' is not lowercase null", obj));
524+
}
525+
else if (obj instanceof String) {
526+
// Strict mode only allows strings with explicit double quotes
527+
throw this.syntaxError(String.format("Strict mode error: Value '%s' is not surrounded by quotes", obj));
528+
}
528529
}
529530
return obj;
530531
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3998,7 +3998,7 @@ public void testStrictModeJSONTokener_expectException(){
39983998
}
39993999

40004000
@Test
4001-
public void test_strictModeWithMisCasedBooleanValue(){
4001+
public void test_strictModeWithMisCasedBooleanOrNullValue(){
40024002
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration().withStrictMode();
40034003

40044004
try{
@@ -4009,6 +4009,10 @@ public void test_strictModeWithMisCasedBooleanValue(){
40094009
JSONObject j2 = new JSONObject("{\"a\":TRUE}", jsonParserConfiguration);
40104010
fail("Expected an exception");
40114011
} catch (JSONException e) { }
4012+
try{
4013+
JSONObject j2 = new JSONObject("{\"a\":nUlL}", jsonParserConfiguration);
4014+
fail("Expected an exception");
4015+
} catch (JSONException e) { }
40124016
}
40134017

40144018
@Test

0 commit comments

Comments
 (0)