Changeset 83260 in webkit


Ignore:
Timestamp:
Apr 7, 2011 11:45:30 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-07 Julien Chaffraix <jchaffraix@codeaurora.org>

Reviewed by Alexey Proskuryakov.

EventSource should only accept UTF-8 charset
https://bugs.webkit.org/show_bug.cgi?id=56942

  • ChangeLog-2011-02-16: Corrected previous commit message. Pointed out by Alexey.
  • http/tests/eventsource/eventsource-bad-mime-type-expected.txt: Updated with the new console message.
  • http/tests/eventsource/eventsource-content-type-charset-expected.txt:
  • http/tests/eventsource/eventsource-content-type-charset.html: Beefed up this test and merged the following test into it. The new tests check that we dispatch a console error if the charset is wrong.
  • http/tests/eventsource/eventsource-content-type-text-event-stream-foobar-expected.txt: Removed.
  • http/tests/eventsource/eventsource-content-type-text-event-stream-foobar.html: Removed.
  • http/tests/eventsource/resources/response-content-type-charset.php: Return the charset passed in the URL. Also added PHP's magic quotes handling as this would make the test fail on Mac.
  • http/tests/eventsource/resources/response-content-type-event-stream-foobar.php: Removed.

2011-04-07 Julien Chaffraix <jchaffraix@codeaurora.org>

Reviewed by Alexey Proskuryakov.

EventSource should only accept UTF-8 charset
https://bugs.webkit.org/show_bug.cgi?id=56942

Following the discussion on bug 45372, this change implements the recommended
way of handling "charset". We only accept UTF-8 but no other encoding. This matches
the encoding of the EventSource and also may fix TomCat that automatically send this
charset.

  • page/EventSource.cpp: (WebCore::EventSource::didReceiveResponse): We now check the charset attribute and if it is not UTF-8, abort the connection and log the error to the console. Also we log if the MIME type is wrong to the console to help debugging (only in the case of an HTTP 200 response though).
Location:
trunk
Files:
3 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r83257 r83260  
     12011-04-07  Julien Chaffraix  <jchaffraix@codeaurora.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        EventSource should only accept UTF-8 charset
     6        https://bugs.webkit.org/show_bug.cgi?id=56942
     7
     8        * ChangeLog-2011-02-16: Corrected previous commit message. Pointed out by Alexey.
     9
     10        * http/tests/eventsource/eventsource-bad-mime-type-expected.txt: Updated with the new console message.
     11
     12        * http/tests/eventsource/eventsource-content-type-charset-expected.txt:
     13        * http/tests/eventsource/eventsource-content-type-charset.html: Beefed up this test and merged
     14        the following test into it. The new tests check that we dispatch a console error if the charset is
     15        wrong.
     16
     17        * http/tests/eventsource/eventsource-content-type-text-event-stream-foobar-expected.txt: Removed.
     18        * http/tests/eventsource/eventsource-content-type-text-event-stream-foobar.html: Removed.
     19
     20        * http/tests/eventsource/resources/response-content-type-charset.php: Return the charset passed
     21        in the URL. Also added PHP's magic quotes handling as this would make the test fail on Mac.
     22
     23        * http/tests/eventsource/resources/response-content-type-event-stream-foobar.php: Removed.
     24
    1252011-04-07  Kent Tamura  <tkent@chromium.org>
    226
  • trunk/LayoutTests/ChangeLog-2011-02-16

    r78737 r83260  
    2740127401
    2740227402        Test that a Content-Type of "text/event-stream; charset=UTF8" works correctly but
    27403         "text/event-stream" does not work.
     27403        "text/event-stream-foobar" does not work.
    2740427404
    2740527405        * http/tests/eventsource/eventsource-content-type-charset-expected.txt: Added.
  • trunk/LayoutTests/http/tests/eventsource/eventsource-bad-mime-type-expected.txt

    r47323 r83260  
     1CONSOLE MESSAGE: line 1: EventSource's response has a MIME type ("text/bogus") that is not "text/event-stream". Aborting the connection.
    12Test EventSource with an event-stream with incorrect mime-type.
    23
  • trunk/LayoutTests/http/tests/eventsource/eventsource-content-type-charset-expected.txt

    r74011 r83260  
     1CONSOLE MESSAGE: line 1: EventSource's response has a charset ("windows-1251") that is not UTF-8. Aborting the connection.
     2CONSOLE MESSAGE: line 1: EventSource's response has a MIME type ("text/event-stream-foobar") that is not "text/event-stream". Aborting the connection.
    13Test for bug 45372: https://bugs.webkit.org/show_bug.cgi?id=45372
    24
    3 Test EventSource with an event-stream with a Content-Type with a charset is still recognized. You should see 2 PASSED below (one for open and one for message).
     5Test EventSource with an event-stream with a Content-Type with a charset is still recognized. You should see 5 PASSED below.
    46
    5 PASSED: got open event
    6 PASSED: got message event
     7PASSED: text/event-stream; charset=UTF-8
     8PASSED: text/event-stream; charset=windows-1251
     9PASSED: text/event-stream; charset=utf-8
     10PASSED: text/event-stream; charset="UTF-8"
     11PASSED: text/event-stream-foobar;
    712
  • trunk/LayoutTests/http/tests/eventsource/eventsource-content-type-charset.html

    r74011 r83260  
    33<body>
    44<p>Test for bug <a href="https://bugs.webkit.org/show_bug.cgi?id=45372">45372</a>: https://bugs.webkit.org/show_bug.cgi?id=45372</p>
    5 <p>Test EventSource with an event-stream with a Content-Type with a charset is still recognized. You should see 2 PASSED below (one for open and one for message).</p>
     5<p>Test EventSource with an event-stream with a Content-Type with a charset is still recognized. You should see 5 PASSED below.</p>
    66<div id="result"></div>
    77<script>
     
    1515}
    1616
    17 var es = new EventSource("resources/response-content-type-charset.php");
     17function shouldGetMessage(es)
     18{
     19    if (es.sawOpen && es.sawMessage && !es.sawError)
     20        log("PASSED: " + es.contentType);
     21    else
     22        log("FAILED: " + es.contentType);
     23}
    1824
    19 es.onopen = function (evt) {
    20     log("PASSED: got open event");
     25function shouldFail(es)
     26{
     27    if (es.sawError && !es.sawOpen && !es.sawMessages)
     28        log("PASSED: " + es.contentType);
     29    else
     30        log("FAILED: " + es.contentType);
     31}
     32
     33var i = 0;
     34var contentTypes = [ 'text/event-stream; charset=UTF-8',
     35                     'text/event-stream; charset=windows-1251',
     36                     'text/event-stream; charset=utf-8',
     37                     'text/event-stream; charset="UTF-8"',
     38                     'text/event-stream-foobar;'
     39                   ];
     40
     41var expectedResultCallback = [ shouldGetMessage,
     42                               shouldFail,
     43                               shouldGetMessage,
     44                               shouldGetMessage,
     45                               shouldFail
     46                             ];
     47
     48function openListener(evt) {
     49    evt.target.sawOpen = true;
    2150};
    2251
    23 es.onmessage = function (evt) {
    24     log("PASSED: got message event");
    25     end();
     52function messageListener(evt) {
     53    evt.target.sawMessage = true;
     54    evt.target.successCallback(evt.target);
     55    evt.target.close();
     56    next();
    2657};
    2758
    28 es.onerror = function () {
    29     log("FAILED: unexpected error event");
    30     end();
     59function errorListener(evt) {
     60    evt.target.sawError = true;
     61    evt.target.successCallback(evt.target);
     62    evt.target.close();
     63    next();
    3164};
    3265
     66function startRequest()
     67{
     68    es = new EventSource("resources/response-content-type-charset.php?contentType=" + escape(contentTypes[i]));
     69    es.onopen = openListener;
     70    es.onmessage = messageListener;
     71    es.onerror = errorListener;
     72    es.successCallback = expectedResultCallback[i];
     73    es.contentType = contentTypes[i];
     74    ++i;
     75}
     76
     77function next() {
     78    if (i >= contentTypes.length) {
     79        end();
     80        return;
     81    }
     82    startRequest();
     83}
     84
    3385function end() {
    34     es.close();
    3586    if (window.layoutTestController)
    3687        layoutTestController.notifyDone();
    3788}
     89startRequest();
    3890</script>
    3991</body>
  • trunk/LayoutTests/http/tests/eventsource/resources/response-content-type-charset.php

    r74011 r83260  
    11<?php
    2 header("Content-Type: text/event-stream; charset=UTF8");
     2$contentType = $_GET["contentType"];
     3// If the magic quotes option is enabled, the charset could be escaped and we
     4// would fail our test. For example, charset="utf-8" would become charset=\"utf-8\".
     5if (get_magic_quotes_gpc()) {
     6    $contentType = stripslashes($contentType);
     7}
     8header("Content-Type: $contentType");
    39?>
    410
     
    612retry: 300
    713data: hello
    8 
  • trunk/Source/WebCore/ChangeLog

    r83259 r83260  
     12011-04-07  Julien Chaffraix  <jchaffraix@codeaurora.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        EventSource should only accept UTF-8 charset
     6        https://bugs.webkit.org/show_bug.cgi?id=56942
     7
     8        Following the discussion on bug 45372, this change implements the recommended
     9        way of handling "charset". We only accept UTF-8 but no other encoding. This matches
     10        the encoding of the EventSource and also may fix TomCat that automatically send this
     11        charset.
     12
     13        * page/EventSource.cpp:
     14        (WebCore::EventSource::didReceiveResponse): We now check the charset attribute and if it is
     15        not UTF-8, abort the connection and log the error to the console. Also we log if the MIME type
     16        is wrong to the console to help debugging (only in the case of an HTTP 200 response though).
     17
    1182011-04-07  Geoffrey Garen  <ggaren@apple.com>
    219
  • trunk/Source/WebCore/page/EventSource.cpp

    r78782 r83260  
    33 * All rights reserved.
    44 * Copyright (C) 2010 Apple Inc. All rights reserved.
     5 * Copyright (C) 2011, Code Aurora Forum. All rights reserved.
    56 *
    67 * Redistribution and use in source and binary forms, with or without
     
    4647#include "ResourceRequest.h"
    4748#include "ResourceResponse.h"
     49#include "ScriptCallStack.h"
    4850#include "ScriptExecutionContext.h"
    4951#include "SerializedScriptValue.h"
     
    181183{
    182184    int statusCode = response.httpStatusCode();
    183     if (statusCode == 200 && response.mimeType() == "text/event-stream") {
     185    bool mimeTypeIsValid = response.mimeType() == "text/event-stream";
     186    bool responseIsValid = statusCode == 200 && mimeTypeIsValid;
     187    if (responseIsValid) {
     188        const String& charset = response.textEncodingName();
     189        // If we have a charset, the only allowed value is UTF-8 (case-insensitive). This should match
     190        // the updated EventSource standard.
     191        responseIsValid = charset.isEmpty() || equalIgnoringCase(charset, "UTF-8");
     192        if (!responseIsValid) {
     193            String message = "EventSource's response has a charset (\"";
     194            message += charset;
     195            message += "\") that is not UTF-8. Aborting the connection.";
     196            // FIXME: We are missing the source line.
     197            scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, 1, String(), 0);
     198        }
     199    } else {
     200        // To keep the signal-to-noise ratio low, we only log 200-response with an invalid MIME type.
     201        if (statusCode == 200 && !mimeTypeIsValid) {
     202            String message = "EventSource's response has a MIME type (\"";
     203            message += response.mimeType();
     204            message += "\") that is not \"text/event-stream\". Aborting the connection.";
     205            // FIXME: We are missing the source line.
     206            scriptExecutionContext()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, message, 1, String(), 0);
     207        }
     208    }
     209
     210    if (responseIsValid) {
    184211        m_state = OPEN;
    185212        dispatchEvent(Event::create(eventNames().openEvent, false, false));
Note: See TracChangeset for help on using the changeset viewer.