Fixes corner case where strict mode isn't working when JSONTokener's next() and back() are called first
This commit is contained in:
@@ -1566,4 +1566,22 @@ public class JSONArrayTest {
|
||||
"[1,null,3]", jsonArray.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void strictModeShouldCheckTrailingCharactersAfterNextAndBack() {
|
||||
JSONParserConfiguration strict =
|
||||
new JSONParserConfiguration().withStrictMode();
|
||||
|
||||
JSONTokener tok = new JSONTokener("[]xxx");
|
||||
|
||||
tok.next();
|
||||
tok.back();
|
||||
|
||||
JSONException exception = assertThrows(
|
||||
JSONException.class,
|
||||
() -> new JSONArray(tok, strict));
|
||||
|
||||
assertTrue(exception.getMessage().contains(
|
||||
"Unparsed characters found at end of input text"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4337,4 +4337,22 @@ public class JSONObjectTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void strictModeShouldCheckTrailingCharactersAfterNextAndBack() {
|
||||
JSONParserConfiguration strict =
|
||||
new JSONParserConfiguration().withStrictMode();
|
||||
|
||||
JSONTokener tok = new JSONTokener("{}xxx");
|
||||
|
||||
tok.next();
|
||||
tok.back();
|
||||
|
||||
JSONException exception = assertThrows(
|
||||
JSONException.class,
|
||||
() -> new JSONObject(tok, strict));
|
||||
|
||||
assertTrue(exception.getMessage().contains(
|
||||
"Unparsed characters found at end of input text"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user