mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -04:00
oops forgot null
This commit is contained in:
parent
fdaeb486ed
commit
c91b728386
@ -513,19 +513,20 @@ public class JSONTokener {
|
|||||||
Object obj = JSONObject.stringToValue(string);
|
Object obj = JSONObject.stringToValue(string);
|
||||||
// if obj is a boolean, look at string
|
// if obj is a boolean, look at string
|
||||||
if (jsonParserConfiguration != null &&
|
if (jsonParserConfiguration != null &&
|
||||||
jsonParserConfiguration.isStrictMode() && obj instanceof Boolean) {
|
jsonParserConfiguration.isStrictMode()) {
|
||||||
if (!"true".equals(string) && !"false".equals(string)) {
|
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));
|
throw this.syntaxError(String.format("Strict mode error: Value '%s' is not lowercase boolean", 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
|
// 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));
|
throw this.syntaxError(String.format("Strict mode error: Value '%s' is not surrounded by quotes", obj));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3998,7 +3998,7 @@ public class JSONObjectTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_strictModeWithMisCasedBooleanValue(){
|
public void test_strictModeWithMisCasedBooleanOrNullValue(){
|
||||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration().withStrictMode();
|
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration().withStrictMode();
|
||||||
|
|
||||||
try{
|
try{
|
||||||
@ -4009,6 +4009,10 @@ public class JSONObjectTest {
|
|||||||
JSONObject j2 = new JSONObject("{\"a\":TRUE}", jsonParserConfiguration);
|
JSONObject j2 = new JSONObject("{\"a\":TRUE}", jsonParserConfiguration);
|
||||||
fail("Expected an exception");
|
fail("Expected an exception");
|
||||||
} catch (JSONException e) { }
|
} catch (JSONException e) { }
|
||||||
|
try{
|
||||||
|
JSONObject j2 = new JSONObject("{\"a\":nUlL}", jsonParserConfiguration);
|
||||||
|
fail("Expected an exception");
|
||||||
|
} catch (JSONException e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user