Skip to content

Commit 0a3175f

Browse files
haruhisa-shinfujii
authored andcommitted
[WebDriver][socket] Titles containing multibyte characters cannot be retrieved correctly
https://bugs.webkit.org/show_bug.cgi?id=270063 Reviewed by Alexey Proskuryakov. If the document title contains multibyte characters such as Japanese or entity references, the "Get Title" result will be garbled. The title string is obtained by JavaScript's "document.title()", and this data is encoded in UTF8. However, the StringBuilder.append() function used to create HTTP messages uses fromLatin1() internally to generate strings from byte data. This seems to be causing the multibyte characters to be garbled. This patch changes to use String::fromUTF8() before concatenation to restore the correct WTF::String even if it contains multibyte characters. Also, the change of get.py is regression test for this issue. This is an export from web-platform-tests/wpt#46584. * Source/WebDriver/socket/HTTPServerSocket.cpp: (WebDriver::HTTPRequestHandler::packHTTPMessage const): * WebDriverTests/imported/w3c/webdriver/tests/classic/get_title/get.py: (test_strip_and_collapse): (test_title_included_entity_references): (test_title_included_multibyte_char): Canonical link: https://commits.webkit.org/279767@main
1 parent f5df91c commit 0a3175f

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Source/WebDriver/socket/HTTPServerSocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ String HTTPRequestHandler::packHTTPMessage(HTTPRequestHandler::Response&& respon
127127
builder.append(EOL);
128128

129129
if (!response.data.isNull())
130-
builder.append(response.data.span());
130+
builder.append(String::fromUTF8(response.data.span()));
131131

132132
return builder.toString();
133133
}

WebDriverTests/imported/w3c/webdriver/tests/classic/get_title/get.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from tests.support.asserts import assert_error, assert_success
1+
from tests.support.asserts import assert_error, assert_success
22

33

44
def get_title(session):
@@ -54,3 +54,17 @@ def test_strip_and_collapse(session, inline):
5454

5555
result = get_title(session)
5656
assert_success(result, "a b c d e")
57+
58+
59+
def test_title_included_entity_references(session, inline):
60+
session.url = inline("<title>&reg; &copy; &cent; &pound; &yen;</title>")
61+
62+
result = get_title(session)
63+
assert_success(result, u'® © ¢ £ ¥')
64+
65+
66+
def test_title_included_multibyte_char(session, inline):
67+
session.url = inline(u"<title>日本語</title>")
68+
69+
result = get_title(session)
70+
assert_success(result, u"日本語")

0 commit comments

Comments
 (0)