Merge pull request #772 from eamonnmcmanus/complexkey

Disallow nested objects and arrays as keys in objects.
This commit is contained in:
Sean Leary
2023-10-01 11:04:40 -05:00
committed by GitHub
4 changed files with 71 additions and 19 deletions

View File

@@ -118,7 +118,7 @@ public class JSONArrayTest {
* Expects a JSONException.
*/
@Test
public void emptStr() {
public void emptyStr() {
String str = "";
try {
assertNull("Should throw an exception", new JSONArray(str));
@@ -460,6 +460,20 @@ public class JSONArrayTest {
Util.checkJSONArrayMaps(jsonArray);
}
/**
* The JSON parser is permissive of unambiguous unquoted keys and values.
* Such JSON text should be allowed, even if it does not strictly conform
* to the spec. However, after being parsed, toString() should emit strictly
* conforming JSON text.
*/
@Test
public void unquotedText() {
String str = "[value1, something!, (parens), foo@bar.com, 23, 23+45]";
JSONArray jsonArray = new JSONArray(str);
List<Object> expected = Arrays.asList("value1", "something!", "(parens)", "foo@bar.com", 23, "23+45");
assertEquals(expected, jsonArray.toList());
}
/**
* Exercise JSONArray.join() by converting a JSONArray into a
* comma-separated string. Since this is very nearly a JSON document,