Skip to content

Commit 9d61cee

Browse files
authored
fix: correctly encode unicode strings to UTF-8 (#167)
1 parent e376ce7 commit 9d61cee

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

playwright/src/main/java/com/microsoft/playwright/impl/Transport.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ public class Transport {
3737
DataInputStream in = new DataInputStream(new BufferedInputStream(input));
3838
readerThread = new ReaderThread(in, incoming);
3939
readerThread.start();
40-
DataOutputStream out = new DataOutputStream(output);
41-
writerThread = new WriterThread(out, outgoing);
40+
writerThread = new WriterThread(output, outgoing);
4241
writerThread.start();
4342
}
4443

@@ -125,17 +124,17 @@ private String readMessage() throws IOException {
125124
}
126125

127126
class WriterThread extends Thread {
128-
final DataOutputStream out;
127+
final OutputStream out;
129128
private final BlockingQueue<String> queue;
130129

131-
private static void writeIntLE(DataOutputStream out, int v) throws IOException {
130+
private static void writeIntLE(OutputStream out, int v) throws IOException {
132131
out.write(v >>> 0 & 255);
133132
out.write(v >>> 8 & 255);
134133
out.write(v >>> 16 & 255);
135134
out.write(v >>> 24 & 255);
136135
}
137136

138-
WriterThread(DataOutputStream out, BlockingQueue<String> queue) {
137+
WriterThread(OutputStream out, BlockingQueue<String> queue) {
139138
this.out = out;
140139
this.queue = queue;
141140
}
@@ -158,8 +157,8 @@ public void run() {
158157
}
159158

160159
private void sendMessage(String message) throws IOException {
161-
int len = message.length();
162-
writeIntLE(out, len);
163-
out.writeBytes(message);
160+
byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
161+
writeIntLE(out, bytes.length);
162+
out.write(bytes);
164163
}
165164
}

playwright/src/test/java/com/microsoft/playwright/TestClick.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ void shouldClimbDomForInnerLabelWithPointerEventsNone() {
511511
assertEquals(true, page.evaluate("__CLICKED"));
512512
}
513513

514+
@Test
515+
void shouldWorkWithUnicodeSelectors() {
516+
page.setContent("<button onclick='javascript:window.__CLICKED=true;'><label style='pointer-events:none'>Найти</label></button>");
517+
page.click("text=Найти");
518+
assertEquals(true, page.evaluate("__CLICKED"));
519+
}
520+
514521
@Test
515522
void shouldClimbUpTo_roleButton_() {
516523
page.setContent("<div role=button onclick='javascript:window.__CLICKED=true;'><div style='pointer-events:none'><span><div>Click target</div></span></div>");

0 commit comments

Comments
 (0)