Skip to content

Commit de2ada0

Browse files
committed
[java] Construct U+FFFF payload at runtime instead of embedding it
Avoids depending on the source file's byte encoding when reading the test.
1 parent 20900bc commit de2ada0

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

java/test/org/openqa/selenium/json/JsonInputTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,19 @@ void shouldBeAbleToReadNonWellFormedDataLongerThanReadBuffer() {
293293

294294
@Test
295295
void shouldReadU_FFFF_AsALiteralCharacterAndNotEndOfInput() {
296-
// U+FFFF is a valid (non-)character; historically it collided with an in-band EOF sentinel
297-
// and was mis-reported as an unterminated string.
298-
try (JsonInput input = newInput("\"a￿b\"")) {
299-
assertThat(input.nextString()).isEqualTo("a￿b");
296+
// U+FFFF is a valid Unicode code unit that historically collided with the in-band EOF
297+
// sentinel and was mis-reported as an unterminated string. Build the strings from
298+
// char values rather than embedding literal U+FFFF so the test is independent of the
299+
// source file's byte encoding.
300+
char nonChar = (char) 0xFFFF;
301+
String literalPayload = "a" + nonChar + "b";
302+
303+
try (JsonInput input = newInput("\"" + literalPayload + "\"")) {
304+
assertThat(input.nextString()).isEqualTo(literalPayload);
300305
}
301306

302307
try (JsonInput input = newInput("\"\\uFFFF\"")) {
303-
assertThat(input.nextString()).isEqualTo("");
308+
assertThat(input.nextString()).isEqualTo(String.valueOf(nonChar));
304309
}
305310
}
306311

0 commit comments

Comments
 (0)