Changeset 85939 in webkit


Ignore:
Timestamp:
May 6, 2011 1:58:44 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-05-06 Joe Mason <jmason@rim.com>

Reviewed by Adam Barth.

WebSocket urls should always be encoded as UTF-8. Relative urls should not be expanded.
https://bugs.webkit.org/show_bug.cgi?id=57138

  • http/tests/websocket/tests/url-with-nonascii-query-expected.txt: Added.
  • http/tests/websocket/tests/url-with-nonascii-query.html: Added.
  • http/tests/websocket/tests/url-parsing-expected.txt: Failure message for relative url has changed since it is no longer expanded.

2011-05-06 Joe Mason <jmason@rim.com>

Reviewed by Adam Barth.

WebSocket urls should always be encoded as UTF-8.
https://bugs.webkit.org/show_bug.cgi?id=57138

Change WebSocket::connect to take the raw URL string and parse it
internally using the simple KURL constructor, which expects an absolute
UTF-8 encoded URL. This ensures that all code that creates a WebSocket
goes through this method instead of completeURL.

Test: http/tests/websocket/tests/url-with-nonascii-query.html

  • bindings/js/JSWebSocketCustom.cpp: (WebCore::JSWebSocketConstructor::constructJSWebSocket): Pass String instead of KURL to WebSocket::connect().
  • websockets/WebSocket.cpp: (WebCore::WebSocket::connect): Now takes a String instead of a KURL and parses it using UTF-8.
  • websockets/WebSocket.h:
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r85937 r85939  
     12011-05-06  Joe Mason  <jmason@rim.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        WebSocket urls should always be encoded as UTF-8. Relative urls should not be expanded.
     6        https://bugs.webkit.org/show_bug.cgi?id=57138
     7
     8        * http/tests/websocket/tests/url-with-nonascii-query-expected.txt: Added.
     9        * http/tests/websocket/tests/url-with-nonascii-query.html: Added.
     10        * http/tests/websocket/tests/url-parsing-expected.txt: Failure message for relative url has changed since it is no longer expanded.
     11
    1122011-05-06  MORITA Hajime  <morrita@google.com>
    213
  • trunk/LayoutTests/http/tests/websocket/tests/url-parsing-expected.txt

    r68914 r85939  
    11CONSOLE 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:8000/applet
     2CONSOLE MESSAGE: line 0: Invalid url for WebSocket /applet
    33CONSOLE MESSAGE: line 0: Wrong url scheme for WebSocket javascript:a
    44CONSOLE MESSAGE: line 0: WebSocket port 25 blocked
  • trunk/Source/WebCore/ChangeLog

    r85938 r85939  
     12011-05-06  Joe Mason  <jmason@rim.com>
     2
     3        Reviewed by Adam Barth.
     4
     5        WebSocket urls should always be encoded as UTF-8.
     6        https://bugs.webkit.org/show_bug.cgi?id=57138
     7
     8        Change WebSocket::connect to take the raw URL string and parse it
     9        internally using the simple KURL constructor, which expects an absolute
     10        UTF-8 encoded URL.  This ensures that all code that creates a WebSocket
     11        goes through this method instead of completeURL.
     12
     13        Test: http/tests/websocket/tests/url-with-nonascii-query.html
     14
     15        * bindings/js/JSWebSocketCustom.cpp:
     16        (WebCore::JSWebSocketConstructor::constructJSWebSocket): Pass String instead of KURL to WebSocket::connect().
     17        * websockets/WebSocket.cpp:
     18        (WebCore::WebSocket::connect): Now takes a String instead of a KURL and parses it using UTF-8.
     19        * websockets/WebSocket.h:
     20
    1212011-05-06  Luke Macpherson   <macpherson@chromium.org>
    222
  • trunk/Source/WebCore/bindings/js/JSWebSocketCustom.cpp

    r84812 r85939  
    5858    if (exec->hadException())
    5959        return throwVMError(exec, createSyntaxError(exec, "wrong URL"));
    60     KURL url = context->completeURL(urlString);
    6160    RefPtr<WebSocket> webSocket = WebSocket::create(context);
    6261    ExceptionCode ec = 0;
    6362    if (exec->argumentCount() < 2)
    64         webSocket->connect(url, ec);
     63        webSocket->connect(urlString, ec);
    6564    else {
    6665        String protocol = ustringToString(exec->argument(1).toString(exec));
    6766        if (exec->hadException())
    6867            return JSValue::encode(JSValue());
    69         webSocket->connect(url, protocol, ec);
     68        webSocket->connect(urlString, protocol, ec);
    7069    }
    7170    setDOMException(exec, ec);
  • trunk/Source/WebCore/websockets/WebSocket.cpp

    r85484 r85939  
    107107}
    108108
    109 void WebSocket::connect(const KURL& url, ExceptionCode& ec)
     109void WebSocket::connect(const String& url, ExceptionCode& ec)
    110110{
    111111    connect(url, String(), ec);
    112112}
    113113
    114 void WebSocket::connect(const KURL& url, const String& protocol, ExceptionCode& ec)
    115 {
    116     LOG(Network, "WebSocket %p connect to %s protocol=%s", this, url.string().utf8().data(), protocol.utf8().data());
    117     m_url = url;
     114void WebSocket::connect(const String& url, const String& protocol, ExceptionCode& ec)
     115{
     116    LOG(Network, "WebSocket %p connect to %s protocol=%s", this, url.utf8().data(), protocol.utf8().data());
     117    m_url = KURL(KURL(), url);
    118118    m_protocol = protocol;
    119119
    120120    if (!m_url.isValid()) {
    121         scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Invalid url for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
     121        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Invalid url for WebSocket " + m_url.string(), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
    122122        m_state = CLOSED;
    123123        ec = SYNTAX_ERR;
     
    126126
    127127    if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) {
    128         scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong url scheme for WebSocket " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
     128        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Wrong url scheme for WebSocket " + m_url.string(), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
    129129        m_state = CLOSED;
    130130        ec = SYNTAX_ERR;
     
    132132    }
    133133    if (m_url.hasFragmentIdentifier()) {
    134         scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "URL has fragment component " + url.string(), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
     134        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "URL has fragment component " + m_url.string(), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
    135135        m_state = CLOSED;
    136136        ec = SYNTAX_ERR;
     
    143143        return;
    144144    }
    145     if (!portAllowed(url)) {
    146         scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, makeString("WebSocket port ", String::number(url.port()), " blocked"), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
     145    if (!portAllowed(m_url)) {
     146        scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, makeString("WebSocket port ", String::number(m_url.port()), " blocked"), 0, scriptExecutionContext()->securityOrigin()->toString(), 0);
    147147        m_state = CLOSED;
    148148        ec = SECURITY_ERR;
  • trunk/Source/WebCore/websockets/WebSocket.h

    r67432 r85939  
    6262        };
    6363
    64         void connect(const KURL&, ExceptionCode&);
    65         void connect(const KURL&, const String& protocol, ExceptionCode&);
     64        void connect(const String& url, ExceptionCode&);
     65        void connect(const String& url, const String& protocol, ExceptionCode&);
    6666
    6767        bool send(const String& message, ExceptionCode&);
Note: See TracChangeset for help on using the changeset viewer.