File tree 2 files changed +18
-0
lines changed
src/test/java/org/json/junit
2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 8
8
import static org .junit .Assert .assertFalse ;
9
9
import static org .junit .Assert .assertNotNull ;
10
10
import static org .junit .Assert .assertNull ;
11
+ import static org .junit .Assert .assertThrows ;
11
12
import static org .junit .Assert .assertTrue ;
12
13
import static org .junit .Assert .fail ;
13
14
@@ -1509,6 +1510,14 @@ public void testRecursiveDepthArrayFor1001Levels() {
1509
1510
new JSONArray (array );
1510
1511
}
1511
1512
1513
+ @ Test
1514
+ public void testStrictModeJSONTokener_expectException (){
1515
+ JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration ().withStrictMode ();
1516
+ JSONTokener tokener = new JSONTokener ("[\" value\" ]invalidCharacters" , jsonParserConfiguration );
1517
+
1518
+ assertThrows (JSONException .class , () -> { new JSONArray (tokener ); });
1519
+ }
1520
+
1512
1521
public static ArrayList <Object > buildNestedArray (int maxDepth ) {
1513
1522
if (maxDepth <= 0 ) {
1514
1523
return new ArrayList <>();
Original file line number Diff line number Diff line change @@ -3853,6 +3853,15 @@ public void clarifyCurrentBehavior() {
3853
3853
assertEquals (j3 .getString ("hex6" ), "0011" );
3854
3854
}
3855
3855
3856
+
3857
+ @ Test
3858
+ public void testStrictModeJSONTokener_expectException (){
3859
+ JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration ().withStrictMode ();
3860
+ JSONTokener tokener = new JSONTokener ("{\" key\" :\" value\" }invalidCharacters" , jsonParserConfiguration );
3861
+
3862
+ assertThrows (JSONException .class , () -> { new JSONObject (tokener ); });
3863
+ }
3864
+
3856
3865
/**
3857
3866
* Method to build nested map of max maxDepth
3858
3867
*
You can’t perform that action at this time.
0 commit comments