Skip to content

Commit

Permalink
[WebDriver][socket] Titles containing multibyte characters cannot be …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
haruhisa-shin authored and fujii committed Jun 6, 2024
1 parent f5df91c commit 0a3175f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Source/WebDriver/socket/HTTPServerSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ String HTTPRequestHandler::packHTTPMessage(HTTPRequestHandler::Response&& respon
builder.append(EOL);

if (!response.data.isNull())
builder.append(response.data.span());
builder.append(String::fromUTF8(response.data.span()));

return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tests.support.asserts import assert_error, assert_success
from tests.support.asserts import assert_error, assert_success


def get_title(session):
Expand Down Expand Up @@ -54,3 +54,17 @@ def test_strip_and_collapse(session, inline):

result = get_title(session)
assert_success(result, "a b c d e")


def test_title_included_entity_references(session, inline):
session.url = inline("<title>&reg; &copy; &cent; &pound; &yen;</title>")

result = get_title(session)
assert_success(result, u'® © ¢ £ ¥')


def test_title_included_multibyte_char(session, inline):
session.url = inline(u"<title>日本語</title>")

result = get_title(session)
assert_success(result, u"日本語")

0 comments on commit 0a3175f

Please sign in to comment.