Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] Add workaround to decode Base64 screenshots non-compliant with RFC 4648 #11179

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion java/src/org/openqa/selenium/OutputType.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public String toString() {
OutputType<byte[]> BYTES = new OutputType<byte[]>() {
@Override
public byte[] convertFromBase64Png(String base64Png) {
return Base64.getDecoder().decode(base64Png);

// https://github.com/SeleniumHQ/selenium/issues/11168:
// Workaround for drivers non-compliant with RFC4648 (e.g. Appium).
// To be removed in future in order to meet W3C WebDriver spec requirements.
String rfc4648CompliantBase64Png = base64Png.replaceAll("\r?\n", "");

return Base64.getDecoder().decode(rfc4648CompliantBase64Png);
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions java/test/org/openqa/selenium/OutputTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ void testBytes() {
}
}

@Test
void testBytesWorkaround() {
// https://github.com/SeleniumHQ/selenium/issues/11168
byte[] bytes = OutputType.BYTES
.convertFromBase64Png("ABA\r\nDA\nB\r\n\r\nAD\r\n");
assertThat(bytes).hasSameSizeAs(TEST_BYTES);
for (int i = 0; i < TEST_BYTES.length; i++) {
assertThat(TEST_BYTES[i]).as("index " + i).isEqualTo(bytes[i]);
}
}

@Test
void testFiles() {
File tmpFile = OutputType.FILE.convertFromBase64Png(TEST_BASE64);
Expand Down