diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index ffe12d6..05a6e34 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -513,18 +513,19 @@ public class JSONTokener { Object obj = JSONObject.stringToValue(string); // if obj is a boolean, look at string if (jsonParserConfiguration != null && - jsonParserConfiguration.isStrictMode() && obj instanceof Boolean) { - if (!"true".equals(string) && !"false".equals(string)) { + jsonParserConfiguration.isStrictMode()) { + if (obj instanceof Boolean && !"true".equals(string) && !"false".equals(string)) { + // Strict mode only allows lowercase true or false throw this.syntaxError(String.format("Strict mode error: Value '%s' is not lowercase boolean", obj)); } - } - - - // Strict mode only allows strings with explicit double quotes - if (jsonParserConfiguration != null && - jsonParserConfiguration.isStrictMode() && - obj instanceof String) { - throw this.syntaxError(String.format("Strict mode error: Value '%s' is not surrounded by quotes", obj)); + else if (obj == JSONObject.NULL && !"null".equals(string)) { + // Strint mode only allows lowercase null + throw this.syntaxError(String.format("Strict mode error: Value '%s' is not lowercase null", obj)); + } + else if (obj instanceof String) { + // Strict mode only allows strings with explicit double quotes + throw this.syntaxError(String.format("Strict mode error: Value '%s' is not surrounded by quotes", obj)); + } } return obj; } diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 50319a8..52a5240 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -3998,7 +3998,7 @@ public class JSONObjectTest { } @Test - public void test_strictModeWithMisCasedBooleanValue(){ + public void test_strictModeWithMisCasedBooleanOrNullValue(){ JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration().withStrictMode(); try{ @@ -4009,6 +4009,10 @@ public class JSONObjectTest { JSONObject j2 = new JSONObject("{\"a\":TRUE}", jsonParserConfiguration); fail("Expected an exception"); } catch (JSONException e) { } + try{ + JSONObject j2 = new JSONObject("{\"a\":nUlL}", jsonParserConfiguration); + fail("Expected an exception"); + } catch (JSONException e) { } } @Test