Apply corner-case fixes under instruction

This commit is contained in:
XIAYM-gh
2026-09-04 08:09:14 +08:00
parent bcbbc89568
commit 359b43d8df
5 changed files with 100 additions and 20 deletions
@@ -1573,7 +1573,6 @@ public class JSONArrayTest {
new JSONParserConfiguration().withStrictMode();
JSONTokener tok = new JSONTokener("[]xxx");
tok.next();
tok.back();
@@ -1584,4 +1583,39 @@ public class JSONArrayTest {
assertTrue(exception.getMessage().contains(
"Unparsed characters found at end of input text"));
}
@Test
public void strictModeShouldCheckTrailingCharactersAfterConsumedWhitespace() {
JSONParserConfiguration strict =
new JSONParserConfiguration().withStrictMode();
JSONTokener tok = new JSONTokener(" []xxx");
tok.next();
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"));
}
@Test
public void strictModeShouldCheckTrailingCharactersAfterNextCleanAndBack() {
JSONParserConfiguration strict =
new JSONParserConfiguration().withStrictMode();
JSONTokener tok = new JSONTokener(" []xxx");
tok.nextClean();
tok.back();
JSONException exception = assertThrows(
JSONException.class,
() -> new JSONArray(tok, strict));
assertTrue(exception.getMessage().contains(
"Unparsed characters found at end of input text"));
}
}
@@ -4343,7 +4343,6 @@ public class JSONObjectTest {
new JSONParserConfiguration().withStrictMode();
JSONTokener tok = new JSONTokener("{}xxx");
tok.next();
tok.back();
@@ -4355,4 +4354,38 @@ public class JSONObjectTest {
"Unparsed characters found at end of input text"));
}
@Test
public void strictModeShouldCheckTrailingCharactersAfterConsumedWhitespace() {
JSONParserConfiguration strict =
new JSONParserConfiguration().withStrictMode();
JSONTokener tok = new JSONTokener(" {}xxx");
tok.next();
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"));
}
@Test
public void strictModeShouldCheckTrailingCharactersAfterNextCleanAndBack() {
JSONParserConfiguration strict =
new JSONParserConfiguration().withStrictMode();
JSONTokener tok = new JSONTokener(" {}xxx");
tok.nextClean();
tok.back();
JSONException exception = assertThrows(
JSONException.class,
() -> new JSONObject(tok, strict));
assertTrue(exception.getMessage().contains(
"Unparsed characters found at end of input text"));
}
}