Skip to content

Commit 3b7ba07

Browse files
committed
add test for invalid input on JSONTokener
1 parent 215f426 commit 3b7ba07

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/java/org/json/junit/JSONTokenerTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,21 @@ public void testAutoClose(){
325325
assertEquals("Stream closed", exception.getMessage());
326326
}
327327
}
328+
329+
@Test
330+
public void testInvalidInput_JSONObject_withoutStrictModel_shouldParseInput() {
331+
String input = "{\"invalidInput\": [],}";
332+
JSONTokener tokener = new JSONTokener(input);
333+
Object value = tokener.nextValue();
334+
assertEquals(new JSONObject(input).toString(), value.toString());
335+
}
336+
337+
@Test
338+
public void testInvalidInput_JSONArray_withoutStrictModel_shouldParseInput() {
339+
String input = "[\"invalidInput\",]";
340+
JSONTokener tokener = new JSONTokener(input);
341+
Object value = tokener.nextValue();
342+
assertEquals(new JSONArray(input).toString(), value.toString());
343+
}
344+
328345
}

0 commit comments

Comments
 (0)