mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-02 11:05:28 -04:00
Merge pull request #948 from Simulant87/947-JSONTokener-configuration-ignored
use JSONParserConfiguration of JSONTokener in JSONObject and JSONArray constructor instead of creating a new one
This commit is contained in:
commit
22f8290840
@ -83,7 +83,7 @@ public class JSONArray implements Iterable<Object> {
|
||||
* If there is a syntax error.
|
||||
*/
|
||||
public JSONArray(JSONTokener x) throws JSONException {
|
||||
this(x, new JSONParserConfiguration());
|
||||
this(x, x.getJsonParserConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -195,7 +195,7 @@ public class JSONObject {
|
||||
* duplicated key.
|
||||
*/
|
||||
public JSONObject(JSONTokener x) throws JSONException {
|
||||
this(x, new JSONParserConfiguration());
|
||||
this(x, x.getJsonParserConfiguration());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@ -1509,6 +1510,14 @@ public class JSONArrayTest {
|
||||
new JSONArray(array);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStrictModeJSONTokener_expectException(){
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration().withStrictMode();
|
||||
JSONTokener tokener = new JSONTokener("[\"value\"]invalidCharacters", jsonParserConfiguration);
|
||||
|
||||
assertThrows(JSONException.class, () -> { new JSONArray(tokener); });
|
||||
}
|
||||
|
||||
public static ArrayList<Object> buildNestedArray(int maxDepth) {
|
||||
if (maxDepth <= 0) {
|
||||
return new ArrayList<>();
|
||||
|
@ -3853,6 +3853,15 @@ public class JSONObjectTest {
|
||||
assertEquals(j3.getString("hex6"), "0011");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStrictModeJSONTokener_expectException(){
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration().withStrictMode();
|
||||
JSONTokener tokener = new JSONTokener("{\"key\":\"value\"}invalidCharacters", jsonParserConfiguration);
|
||||
|
||||
assertThrows(JSONException.class, () -> { new JSONObject(tokener); });
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to build nested map of max maxDepth
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user