Skip to content

Commit 2aa0f5a

Browse files
committed
[java] read selenium manager output as UTF-8 #13653
1 parent 17ba2aa commit 2aa0f5a

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

java/src/org/openqa/selenium/io/CircularOutputStream.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,23 @@ public void close() {
8585
}
8686

8787
@Override
88-
public synchronized String toString() {
88+
public String toString() {
89+
return toString(Charset.defaultCharset());
90+
}
91+
92+
public synchronized String toString(Charset encoding) {
8993
int size = filled ? buffer.length : end;
9094
byte[] toReturn = new byte[size];
9195

9296
// Handle the partially filled array as a special case
9397
if (!filled) {
9498
System.arraycopy(buffer, 0, toReturn, 0, end);
95-
return new String(toReturn, Charset.defaultCharset());
99+
return new String(toReturn, encoding);
96100
}
97101

98102
int n = buffer.length - end;
99103
System.arraycopy(buffer, end, toReturn, 0, n);
100104
System.arraycopy(buffer, 0, toReturn, n, end);
101-
return new String(toReturn, Charset.defaultCharset());
105+
return new String(toReturn, encoding);
102106
}
103107
}

java/src/org/openqa/selenium/manager/SeleniumManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.io.IOException;
2525
import java.io.InputStream;
26+
import java.nio.charset.StandardCharsets;
2627
import java.nio.file.Files;
2728
import java.nio.file.Path;
2829
import java.nio.file.Paths;
@@ -141,7 +142,7 @@ private static Result runCommand(Path binary, List<String> arguments) {
141142
process.shutdown();
142143
}
143144
code = process.exitValue();
144-
output = process.getOutput();
145+
output = process.getOutput(StandardCharsets.UTF_8);
145146
} catch (Exception e) {
146147
throw new WebDriverException("Failed to run command: " + arguments, e);
147148
}

java/src/org/openqa/selenium/os/ExternalProcess.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.InputStream;
2525
import java.io.OutputStream;
2626
import java.io.UncheckedIOException;
27+
import java.nio.charset.Charset;
2728
import java.time.Duration;
2829
import java.util.ArrayList;
2930
import java.util.Collections;
@@ -254,7 +255,18 @@ public ExternalProcess(Process process, CircularOutputStream outputStream, Threa
254255
* @return stdout and stderr as String in Charset.defaultCharset() encoding
255256
*/
256257
public String getOutput() {
257-
return outputStream.toString();
258+
return getOutput(Charset.defaultCharset());
259+
}
260+
261+
/**
262+
* The last N bytes of the combined stdout and stderr as String, the value of N is set while
263+
* building the OsProcess.
264+
*
265+
* @param encoding the encoding to decode the stream
266+
* @return stdout and stderr as String in the given encoding
267+
*/
268+
public String getOutput(Charset encoding) {
269+
return outputStream.toString(encoding);
258270
}
259271

260272
public boolean isAlive() {

0 commit comments

Comments
 (0)