Changeset 52478 in webkit
- Timestamp:
- Dec 21, 2009 8:47:46 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r52477 r52478 1 2009-12-21 Fumitoshi Ukai <ukai@chromium.org> 2 3 Reviewed by Alexey Proskuryakov. 4 5 Invalid url should raise SYNTAX_ERR exception. 6 https://bugs.webkit.org/show_bug.cgi?id=32700 7 8 * websocket/tests/bad-sub-protocol-expected.txt: add CONSOLE MESSAGEs 9 * websocket/tests/script-tests/url-parsing.js: add invalid url tests. 10 Also changed url from ws://127.0.0.1/ to ws://127.0.0.1:8880/websocket/tests/simple to make it sure no errors on console message for these tests by not receiving unexpected response from 127.0.0.1:80 11 * websocket/tests/url-parsing-expected.txt: 12 1 13 2009-12-21 Dirk Pranke <dpranke@chromium.org> 2 14 -
trunk/LayoutTests/websocket/tests/bad-sub-protocol-expected.txt
r52402 r52478 1 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '' 2 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u0000' 3 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u0009' 4 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u001B' 5 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u007F' 6 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u0080' 7 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\u3042' 8 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uFFFF' 9 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '' 10 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uFFFE' 11 CONSOLE MESSAGE: line 0: Wrong protocol for WebSocket '\uD840\uDC0B' 1 12 Test WebSocket bad sub-protocol names. 2 13 -
trunk/LayoutTests/websocket/tests/script-tests/url-parsing.js
r52402 r52478 1 1 description("Test WebSocket URL parsing."); 2 3 // Invalid url will fail to be parsed. 4 shouldThrow('new WebSocket("ws://javascript:a")'); 2 5 3 6 // Can't use relative URLs - because spec says so, and because the scheme is different anyway. 4 7 shouldThrow('new WebSocket("/applet")'); 5 8 9 // Non ws URL is not allowed. 10 shouldThrow('new WebSocket("javascript:a")'); 11 6 12 // UA is allowed to block access to some ports, which we do. 7 13 shouldThrow('new WebSocket("ws://127.0.0.1:25/")'); 8 14 9 // This is what we currently do, but not what the spec says (as of Editor's Draft 1 December 2009).10 shouldBe('(new WebSocket("ws://127.0.0.1/a/../")).URL', '"ws://127.0.0.1/"'); 11 12 shouldBe('(new WebSocket("ws://127.0.0.1 /path?")).URL', '"ws://127.0.0.1/path?"');13 shouldBe('(new WebSocket("ws://127.0.0.1 /path?k=v")).URL', '"ws://127.0.0.1/path?k=v"');15 // Resolve the url string using the resolve a Web address algorithm. 16 // Use 127.0.0.1:8880 and existing ws handler to make sure we don't receive unexpected response (so no console message appears) 17 shouldBe('(new WebSocket("ws://127.0.0.1:8880/a/../websocket/tests/simple")).URL', '"ws://127.0.0.1:8880/websocket/tests/simple"'); 18 shouldBe('(new WebSocket("ws://127.0.0.1:8880/websocket/tests/simple?")).URL', '"ws://127.0.0.1:8880/websocket/tests/simple?"'); 19 shouldBe('(new WebSocket("ws://127.0.0.1:8880/websocket/tests/simple?k=v")).URL', '"ws://127.0.0.1:8880/websocket/tests/simple?k=v"'); 14 20 15 21 // draft-hixie-thewebsocketprotocol-60 says If /url/ has a <fragment> -
trunk/LayoutTests/websocket/tests/url-parsing-expected.txt
r52402 r52478 1 CONSOLE MESSAGE: line 0: Invalid url for WebSocket ws://javascript:a 2 CONSOLE MESSAGE: line 0: Wrong url scheme for WebSocket http://127.0.0.1:8880/applet 3 CONSOLE MESSAGE: line 0: Wrong url scheme for WebSocket javascript:a 4 CONSOLE MESSAGE: line 0: WebSocket port 25 blocked 5 CONSOLE MESSAGE: line 0: URL has fragment component ws://127.0.0.1/path# 6 CONSOLE MESSAGE: line 0: URL has fragment component ws://127.0.0.1/path#fragment 1 7 Test WebSocket URL parsing. 2 8 3 9 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 4 10 11 PASS new WebSocket("ws://javascript:a") threw exception Error: SYNTAX_ERR: DOM Exception 12. 5 12 PASS new WebSocket("/applet") threw exception Error: SYNTAX_ERR: DOM Exception 12. 13 PASS new WebSocket("javascript:a") threw exception Error: SYNTAX_ERR: DOM Exception 12. 6 14 PASS new WebSocket("ws://127.0.0.1:25/") threw exception Error: SECURITY_ERR: DOM Exception 18. 7 PASS (new WebSocket("ws://127.0.0.1 /a/../")).URL is "ws://127.0.0.1/"8 PASS (new WebSocket("ws://127.0.0.1 /path?")).URL is "ws://127.0.0.1/path?"9 PASS (new WebSocket("ws://127.0.0.1 /path?k=v")).URL is "ws://127.0.0.1/path?k=v"15 PASS (new WebSocket("ws://127.0.0.1:8880/a/../websocket/tests/simple")).URL is "ws://127.0.0.1:8880/websocket/tests/simple" 16 PASS (new WebSocket("ws://127.0.0.1:8880/websocket/tests/simple?")).URL is "ws://127.0.0.1:8880/websocket/tests/simple?" 17 PASS (new WebSocket("ws://127.0.0.1:8880/websocket/tests/simple?k=v")).URL is "ws://127.0.0.1:8880/websocket/tests/simple?k=v" 10 18 PASS new WebSocket("ws://127.0.0.1/path#") threw exception Error: SYNTAX_ERR: DOM Exception 12. 11 19 PASS new WebSocket("ws://127.0.0.1/path#fragment") threw exception Error: SYNTAX_ERR: DOM Exception 12. -
trunk/WebCore/ChangeLog
r52469 r52478 1 2009-12-21 Fumitoshi Ukai <ukai@chromium.org> 2 3 Reviewed by Alexey Proskuryakov. 4 5 Invalid url should raise SYNTAX_ERR exception. 6 https://bugs.webkit.org/show_bug.cgi?id=32700 7 8 Check url is valid in WebSocket::connect. 9 Also log the detailed reason of websocket failures to console. 10 11 * websockets/WebSocket.cpp: 12 (WebCore::encodeProtocolString): 13 (WebCore::WebSocket::connect): 14 1 15 2009-12-21 Anders Carlsson <andersca@apple.com> 2 16 -
trunk/WebCore/websockets/WebSocket.cpp
r52402 r52478 44 44 #include "MessageEvent.h" 45 45 #include "ScriptExecutionContext.h" 46 #include "StringBuilder.h" 46 47 #include "WebSocketChannel.h" 47 48 #include <wtf/StdLibExtras.h> … … 49 50 namespace WebCore { 50 51 51 static bool isValidProtocolString(const WebCore::String& protocol)52 static bool isValidProtocolString(const String& protocol) 52 53 { 53 54 if (protocol.isNull()) … … 63 64 } 64 65 66 static String encodeProtocolString(const String& protocol) 67 { 68 StringBuilder builder; 69 for (size_t i = 0; i < protocol.length(); i++) { 70 if (protocol[i] < 0x20 || protocol[i] > 0x7E) 71 builder.append(String::format("\\u%04X", protocol[i])); 72 else if (protocol[i] == 0x5c) 73 builder.append("\\\\"); 74 else 75 builder.append(protocol[i]); 76 } 77 return builder.toString(); 78 } 79 65 80 #if USE(V8) 66 81 … … 102 117 m_protocol = protocol; 103 118 119 if (!m_url.isValid()) { 120 scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Invalid url for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString()); 121 m_state = CLOSED; 122 ec = SYNTAX_ERR; 123 return; 124 } 125 104 126 if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) { 105 LOG(Network, "Wrong url scheme for WebSocket %s", url.string().utf8().data());127 scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong url scheme for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString()); 106 128 m_state = CLOSED; 107 129 ec = SYNTAX_ERR; … … 109 131 } 110 132 if (m_url.hasFragmentIdentifier()) { 111 LOG(Network, "URL has fragment component %s", url.string().utf8().data());133 scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "URL has fragment component " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString()); 112 134 m_state = CLOSED; 113 135 ec = SYNTAX_ERR; … … 115 137 } 116 138 if (!isValidProtocolString(m_protocol)) { 117 LOG(Network, "Wrong protocol for WebSocket %s", m_protocol.utf8().data());139 scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong protocol for WebSocket '" + encodeProtocolString(m_protocol) + "'", 0, scriptExecutionContext()->securityOrigin()->toString()); 118 140 m_state = CLOSED; 119 141 ec = SYNTAX_ERR; … … 121 143 } 122 144 if (!portAllowed(url)) { 123 LOG(Network, "WebSocket port %d blocked", url.port());145 scriptExecutionContext()->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, String::format("WebSocket port %d blocked", url.port()), 0, scriptExecutionContext()->securityOrigin()->toString()); 124 146 m_state = CLOSED; 125 147 ec = SECURITY_ERR;
Note: See TracChangeset
for help on using the changeset viewer.