Diff
Modified: trunk/LayoutTests/ChangeLog (134514 => 134515)
--- trunk/LayoutTests/ChangeLog 2012-11-14 01:27:43 UTC (rev 134514)
+++ trunk/LayoutTests/ChangeLog 2012-11-14 01:52:35 UTC (rev 134515)
@@ -1,3 +1,22 @@
+2012-11-13 Kenichi Ishibashi <ba...@chromium.org>
+
+ [WebSocket] send() and close() should not throw an exception for an unpaired surrogate but use the replacement character
+ https://bugs.webkit.org/show_bug.cgi?id=101569
+
+ Reviewed by Alexey Proskuryakov.
+
+ - Updated tests which try to send unpaired surrogates.
+ These tests should not throw SYNTAX_ERR.
+ - Add a test that checks whether WebKit throws SYNTAX_ERR when a close
+ reason is too long.
+
+ * http/tests/websocket/tests/hybi/close-reason-too-long-expected.txt: Added.
+ * http/tests/websocket/tests/hybi/close-reason-too-long.html: Ditto.
+ * http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt: Updated.
+ * http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html: Ditto.
+ * http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt: Ditto.
+ * http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html: Ditto.
+
2012-11-13 Christophe Dumez <christophe.du...@intel.com>
Make HTMLLegendElement.form behave according to specification
Copied: trunk/LayoutTests/http/tests/websocket/tests/hybi/close-reason-too-long-expected.txt (from rev 134514, trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt) (0 => 134515)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/close-reason-too-long-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/close-reason-too-long-expected.txt 2012-11-14 01:52:35 UTC (rev 134515)
@@ -0,0 +1,11 @@
+CONSOLE MESSAGE: WebSocket close message is too long.
+Checks whether SYNTAX_ERR is thrown when attempting to send too long reason.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+Connected.
+PASS SYNTAX_ERR was thrown.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Copied: trunk/LayoutTests/http/tests/websocket/tests/hybi/close-reason-too-long.html (from rev 134514, trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html) (0 => 134515)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/close-reason-too-long.html (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/close-reason-too-long.html 2012-11-14 01:52:35 UTC (rev 134515)
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script type="text/_javascript_">
+description("Checks whether SYNTAX_ERR is thrown when attempting to send too long reason.");
+
+window.jsTestIsAsync = true;
+
+var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/echo");
+var message;
+var longReason = '';
+for (var i = 0; i < 124; ++i)
+ longReason += 'a';
+
+ws._onopen_ = function()
+{
+ debug("Connected.");
+ try {
+ ws.close(1000, longReason);
+ testFailed('SYNTAX_ERR should be thrown.');
+ } catch (e) {
+ if (e.name == 'SYNTAX_ERR')
+ testPassed('SYNTAX_ERR was thrown.');
+ else
+ testFailed('Unexpected exception: ' + e);
+ }
+ ws.close();
+};
+
+ws._onmessage_ = function (event)
+{
+ message = event.data;
+ testFailed("onmessage() was called. (message = \"" + message + "\")");
+};
+
+ws._onclose_ = function()
+{
+ finishJSTest();
+};
+
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt (134514 => 134515)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt 2012-11-14 01:27:43 UTC (rev 134514)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason-expected.txt 2012-11-14 01:52:35 UTC (rev 134515)
@@ -1,10 +1,9 @@
-CONSOLE MESSAGE: WebSocket close message contains invalid character(s).
-Checks whether SYNTAX_ERR is thrown when attemping to close the connection with unpaired surrogates.
+Checks whether unpaired surrogates in a close reason are silently converted to U+FFFD and SYNTAX_ERR is not thrown.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Connected.
-PASS SYNTAX_ERR was thrown.
+PASS closeEvent.wasClean is true
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html (134514 => 134515)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html 2012-11-14 01:27:43 UTC (rev 134514)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-close-reason.html 2012-11-14 01:52:35 UTC (rev 134515)
@@ -7,35 +7,30 @@
<div id="description"></div>
<div id="console"></div>
<script type="text/_javascript_">
-description("Checks whether SYNTAX_ERR is thrown when attemping to close the connection with unpaired surrogates.");
+description("Checks whether unpaired surrogates in a close reason are silently converted to U+FFFD and SYNTAX_ERR is not thrown.");
window.jsTestIsAsync = true;
var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/echo");
+var message;
+var closeEvent;
ws._onopen_ = function()
{
debug("Connected.");
- try {
- ws.close(1000, '\uD807');
- testFailed('SYNTAX_ERR should be thrown.');
- } catch(e) {
- if (e.name == 'SYNTAX_ERR')
- testPassed('SYNTAX_ERR was thrown.');
- else
- testFailed('Unexpected exception: ' + e);
- }
- ws.close();
+ ws.close(1000, '\uD807');
};
ws._onmessage_ = function (event)
{
- var message = event.data;
+ message = event.data;
testFailed("onmessage() was called. (message = \"" + message + "\")");
};
-ws._onclose_ = function()
+ws._onclose_ = function(event)
{
+ closeEvent = event;
+ shouldBeTrue("closeEvent.wasClean");
finishJSTest();
};
Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt (134514 => 134515)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt 2012-11-14 01:27:43 UTC (rev 134514)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message-expected.txt 2012-11-14 01:52:35 UTC (rev 134515)
@@ -1,10 +1,9 @@
-CONSOLE MESSAGE: Websocket message contains invalid character(s).
-Checks whether SYNTAX_ERR is thrown when attemping to send unpaired surrogates.
+Checks whether unpaired surrogates are replaced with U+FFFD.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Connected.
-PASS SYNTAX_ERR was thrown.
+PASS message is '�'
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html (134514 => 134515)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html 2012-11-14 01:27:43 UTC (rev 134514)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/unpaired-surrogates-in-message.html 2012-11-14 01:52:35 UTC (rev 134515)
@@ -7,31 +7,23 @@
<div id="description"></div>
<div id="console"></div>
<script type="text/_javascript_">
-description("Checks whether SYNTAX_ERR is thrown when attemping to send unpaired surrogates.");
+description("Checks whether unpaired surrogates are replaced with U+FFFD.");
window.jsTestIsAsync = true;
var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/echo");
+var message;
ws._onopen_ = function()
{
debug("Connected.");
- try {
- ws.send('\uD807');
- testFailed('SYNTAX_ERR should be thrown.');
- } catch(e) {
- if (e.name == 'SYNTAX_ERR')
- testPassed('SYNTAX_ERR was thrown.');
- else
- testFailed('Unexpected exception: ' + e);
- }
- ws.close();
+ ws.send("\uD807");
};
ws._onmessage_ = function (event)
{
- var message = event.data;
- testFailed("onmessage() was called. (message = \"" + message + "\")");
+ message = event.data;
+ shouldBe("message", "'\uFFFD'");
ws.close();
};
Modified: trunk/Source/WebCore/ChangeLog (134514 => 134515)
--- trunk/Source/WebCore/ChangeLog 2012-11-14 01:27:43 UTC (rev 134514)
+++ trunk/Source/WebCore/ChangeLog 2012-11-14 01:52:35 UTC (rev 134515)
@@ -1,3 +1,25 @@
+2012-11-13 Kenichi Ishibashi <ba...@chromium.org>
+
+ [WebSocket] send() and close() should not throw an exception for an unpaired surrogate but use the replacement character
+ https://bugs.webkit.org/show_bug.cgi?id=101569
+
+ Reviewed by Alexey Proskuryakov.
+
+ Replace unpaired surrogates with replacing character (U+FFFD) when
+ encoding text messages and close reasons. This change is aimed at
+ following the changes on the WebSocket API specification.
+
+ Test: http/tests/websocket/tests/hybi/close-reason-too-long.html
+
+ * Modules/websockets/WebSocket.cpp:
+ (WebCore::WebSocket::close):
+ Use String::StrictConversionReplacingUnpairedSurrogatesWithFFFD mode to encode
+ text message. Remove invalid utf-8 check.
+ * Modules/websockets/WebSocketChannel.cpp:
+ (WebCore::WebSocketChannel::send):
+ Use String::StrictConversionReplacingUnpairedSurrogatesWithFFFD mode to encode
+ close reason. Remove invalid utf-8 check.
+
2012-11-13 Christophe Dumez <christophe.du...@intel.com>
Make HTMLLegendElement.form behave according to specification
Modified: trunk/Source/WebCore/Modules/websockets/WebSocket.cpp (134514 => 134515)
--- trunk/Source/WebCore/Modules/websockets/WebSocket.cpp 2012-11-14 01:27:43 UTC (rev 134514)
+++ trunk/Source/WebCore/Modules/websockets/WebSocket.cpp 2012-11-14 01:52:35 UTC (rev 134515)
@@ -371,18 +371,12 @@
ec = INVALID_ACCESS_ERR;
return;
}
- CString utf8 = reason.utf8(String::StrictConversion);
+ CString utf8 = reason.utf8(String::StrictConversionReplacingUnpairedSurrogatesWithFFFD);
if (utf8.length() > maxReasonSizeInBytes) {
scriptExecutionContext()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "WebSocket close message is too long.");
ec = SYNTAX_ERR;
return;
}
- // Checks whether reason is valid utf8.
- if (utf8.isNull() && reason.length()) {
- scriptExecutionContext()->addConsoleMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "WebSocket close message contains invalid character(s).");
- ec = SYNTAX_ERR;
- return;
- }
}
if (m_state == CLOSING || m_state == CLOSED)
Modified: trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp (134514 => 134515)
--- trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp 2012-11-14 01:27:43 UTC (rev 134514)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketChannel.cpp 2012-11-14 01:52:35 UTC (rev 134515)
@@ -137,9 +137,7 @@
ThreadableWebSocketChannel::SendResult WebSocketChannel::send(const String& message)
{
LOG(Network, "WebSocketChannel %p send %s", this, message.utf8().data());
- CString utf8 = message.utf8(String::StrictConversion);
- if (utf8.isNull() && message.length())
- return InvalidMessage;
+ CString utf8 = message.utf8(String::StrictConversionReplacingUnpairedSurrogatesWithFFFD);
enqueueTextFrame(utf8);
// According to WebSocket API specification, WebSocket.send() should return void instead
// of boolean. However, our implementation still returns boolean due to compatibility