mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-03 03:15:32 -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.
|
* If there is a syntax error.
|
||||||
*/
|
*/
|
||||||
public JSONArray(JSONTokener x) throws JSONException {
|
public JSONArray(JSONTokener x) throws JSONException {
|
||||||
this(x, new JSONParserConfiguration());
|
this(x, x.getJsonParserConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -195,7 +195,7 @@ public class JSONObject {
|
|||||||
* duplicated key.
|
* duplicated key.
|
||||||
*/
|
*/
|
||||||
public JSONObject(JSONTokener x) throws JSONException {
|
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.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@ -1509,6 +1510,14 @@ public class JSONArrayTest {
|
|||||||
new JSONArray(array);
|
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) {
|
public static ArrayList<Object> buildNestedArray(int maxDepth) {
|
||||||
if (maxDepth <= 0) {
|
if (maxDepth <= 0) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
|
@ -3853,6 +3853,15 @@ public class JSONObjectTest {
|
|||||||
assertEquals(j3.getString("hex6"), "0011");
|
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
|
* Method to build nested map of max maxDepth
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user