mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-09 20:14:28 +08:00
Generalize the logic to disallow nested objects and arrays as keys in objects.
Fixes #771.
This commit is contained in:
@@ -2224,6 +2224,24 @@ public class JSONObjectTest {
|
||||
"Expected a ',' or '}' at 15 [character 16 line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
// key is a nested map
|
||||
String str = "{{\"foo\": \"bar\"}: \"baz\"}";
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Nested object not expected here. at 2 [character 3 line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
// key is a nested array containing a map
|
||||
String str = "{\"a\": 1, [{\"foo\": \"bar\"}]: \"baz\"}";
|
||||
assertNull("Expected an exception",new JSONObject(str));
|
||||
} catch (JSONException e) {
|
||||
assertEquals("Expecting an exception message",
|
||||
"Nested array not expected here. at 10 [character 11 line 1]",
|
||||
e.getMessage());
|
||||
}
|
||||
try {
|
||||
// \0 after ,
|
||||
String str = "{\"myKey\":true, \0\"myOtherKey\":false}";
|
||||
|
Reference in New Issue
Block a user