Diff
Modified: trunk/LayoutTests/ChangeLog (103473 => 103474)
--- trunk/LayoutTests/ChangeLog 2011-12-22 00:25:18 UTC (rev 103473)
+++ trunk/LayoutTests/ChangeLog 2011-12-22 00:37:11 UTC (rev 103474)
@@ -1,3 +1,19 @@
+2011-12-21 Per-Erik Brodin <per-erik.bro...@ericsson.com>
+
+ Discard event data not followed by an empty line before eof when parsing an event-stream
+ https://bugs.webkit.org/show_bug.cgi?id=68833
+
+ Reviewed by Alexey Proskuryakov.
+
+ * http/tests/eventsource/eventsource-eof-expected.txt: Added.
+ * http/tests/eventsource/eventsource-eof.html: Added.
+ * http/tests/eventsource/eventsource-reconnect-expected.txt: Updated.
+ * http/tests/eventsource/eventsource-reconnect.html: Added lastEventId check.
+ * http/tests/eventsource/resources/es-eof.php: Added.
+ * http/tests/eventsource/resources/reconnect.php: Added data to be discarded.
+ * http/tests/eventsource/resources/response-content-type-charset.php: Added empty line before eof.
+ * http/tests/eventsource/resources/simple-event-stream.asis: Added empty line before eof.
+
2011-12-21 Scott Franklin <scot...@google.com>
Reviewed by Eric Carlson.
Added: trunk/LayoutTests/http/tests/eventsource/eventsource-eof-expected.txt (0 => 103474)
--- trunk/LayoutTests/http/tests/eventsource/eventsource-eof-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/eventsource/eventsource-eof-expected.txt 2011-12-22 00:37:11 UTC (rev 103474)
@@ -0,0 +1,7 @@
+Test that EventSource discards event data if there is no newline before eof. Should print a series of PASS messages followed by DONE.
+
+PASS: got event with expected data, lastEventId, and type
+PASS: got event with expected data, lastEventId, and type
+PASS: got event with expected data, lastEventId, and type
+DONE
+
Added: trunk/LayoutTests/http/tests/eventsource/eventsource-eof.html (0 => 103474)
--- trunk/LayoutTests/http/tests/eventsource/eventsource-eof.html (rev 0)
+++ trunk/LayoutTests/http/tests/eventsource/eventsource-eof.html 2011-12-22 00:37:11 UTC (rev 103474)
@@ -0,0 +1,48 @@
+<html>
+<body>
+<p>Test that EventSource discards event data if there is no newline before eof. Should print a series of PASS messages followed by DONE.</p>
+<div id="result"></div>
+<script>
+function log(msg) {
+ document.getElementById("result").innerHTML += msg + "<br>";
+}
+
+if (window.layoutTestController) {
+ layoutTestController.dumpAsText();
+ layoutTestController.waitUntilDone();
+}
+
+var count = 1;
+
+var es = new EventSource("resources/es-eof.php");
+
+es._onerror_ = function () {
+ if (count++ == 3) {
+ es.close();
+ if (window.layoutTestController)
+ layoutTestController.notifyDone();
+ }
+};
+
+es._onmessage_ = function (evt) {
+ if (evt.data == ("DATA" + count)) {
+ if (evt.lastEventId == count) {
+ if (evt.type == "message")
+ log("PASS: got event with expected data, lastEventId, and type");
+ else
+ log("FAIL: got expected data and lastEventId but type is wrong");
+ }
+ else if (evt.type == "message")
+ log("FAIL: got expected data but lastEventId is wrong");
+ else
+ log("FAIL: got expected data but lastEventId and type are wrong");
+ }
+ else if (count == 3 && evt.data == "DATA" && evt.lastEventId == "3.1" && evt.type == "msg")
+ log("DONE");
+ else
+ log("FAIL: got unexpected message event");
+};
+es.addEventListener("msg", es.onmessage);
+</script>
+</body>
+</html>
Modified: trunk/LayoutTests/http/tests/eventsource/eventsource-reconnect-expected.txt (103473 => 103474)
--- trunk/LayoutTests/http/tests/eventsource/eventsource-reconnect-expected.txt 2011-12-22 00:25:18 UTC (rev 103473)
+++ trunk/LayoutTests/http/tests/eventsource/eventsource-reconnect-expected.txt 2011-12-22 00:37:11 UTC (rev 103474)
@@ -5,7 +5,7 @@
PASS: got lastEventId "77"
PASS: state is CONNECTING
PASS: state is OPEN
-PASS: Last-Event-ID header was correct
+PASS: Last-Event-ID header and the lastEventId property were correct
PASS: state is CLOSED
DONE
Modified: trunk/LayoutTests/http/tests/eventsource/eventsource-reconnect.html (103473 => 103474)
--- trunk/LayoutTests/http/tests/eventsource/eventsource-reconnect.html 2011-12-22 00:25:18 UTC (rev 103473)
+++ trunk/LayoutTests/http/tests/eventsource/eventsource-reconnect.html 2011-12-22 00:37:11 UTC (rev 103474)
@@ -41,10 +41,12 @@
else
log("FAIL: unexpected lastEventId \"" + evt.lastEventId + "\"");
} else {
- if (evt.data == "77")
- log("PASS: Last-Event-ID header was correct");
+ if (evt.data != "77")
+ log("FAIL: Last-Event-ID header was incorrect/missing");
+ else if (evt.lastEventId != "77")
+ log("FAIL: the lastEventId property was incorrect");
else
- log("FAIL: Last-Event-ID header was incorrect/missing");
+ log("PASS: Last-Event-ID header and the lastEventId property were correct");
}
};
Added: trunk/LayoutTests/http/tests/eventsource/resources/es-eof.php (0 => 103474)
--- trunk/LayoutTests/http/tests/eventsource/resources/es-eof.php (rev 0)
+++ trunk/LayoutTests/http/tests/eventsource/resources/es-eof.php 2011-12-22 00:37:11 UTC (rev 103474)
@@ -0,0 +1,13 @@
+<?php
+header("Content-Type: text/event-stream");
+
+$id = floatval($_SERVER['HTTP_LAST_EVENT_ID']) + 1;
+
+echo "retry: 0\n";
+echo "id: " . $id . "\n";
+echo "data: DATA" . intval($id) . "\n\n";
+
+echo "id: " . ($id + 0.1) . "\n";
+echo "event: msg\n";
+echo "data: DATA" . str_repeat("\n", $id - 1);
+?>
Modified: trunk/LayoutTests/http/tests/eventsource/resources/reconnect.php (103473 => 103474)
--- trunk/LayoutTests/http/tests/eventsource/resources/reconnect.php 2011-12-22 00:25:18 UTC (rev 103473)
+++ trunk/LayoutTests/http/tests/eventsource/resources/reconnect.php 2011-12-22 00:37:11 UTC (rev 103474)
@@ -8,5 +8,6 @@
echo "id: 77\n";
echo "retry: 300\n";
echo "data: hello\n\n";
+ echo "data: discarded";
}
?>
Modified: trunk/LayoutTests/http/tests/eventsource/resources/response-content-type-charset.php (103473 => 103474)
--- trunk/LayoutTests/http/tests/eventsource/resources/response-content-type-charset.php 2011-12-22 00:25:18 UTC (rev 103473)
+++ trunk/LayoutTests/http/tests/eventsource/resources/response-content-type-charset.php 2011-12-22 00:37:11 UTC (rev 103474)
@@ -11,3 +11,4 @@
id: 77
retry: 300
data: hello
+
Modified: trunk/LayoutTests/http/tests/eventsource/resources/simple-event-stream.asis (103473 => 103474)
--- trunk/LayoutTests/http/tests/eventsource/resources/simple-event-stream.asis 2011-12-22 00:25:18 UTC (rev 103473)
+++ trunk/LayoutTests/http/tests/eventsource/resources/simple-event-stream.asis 2011-12-22 00:37:11 UTC (rev 103474)
@@ -1,3 +1,4 @@
Content-Type: text/event-stream
data: hello
+
Modified: trunk/Source/WebCore/ChangeLog (103473 => 103474)
--- trunk/Source/WebCore/ChangeLog 2011-12-22 00:25:18 UTC (rev 103473)
+++ trunk/Source/WebCore/ChangeLog 2011-12-22 00:37:11 UTC (rev 103474)
@@ -1,3 +1,17 @@
+2011-12-21 Per-Erik Brodin <per-erik.bro...@ericsson.com>
+
+ Discard event data not followed by an empty line before eof when parsing an event-stream
+ https://bugs.webkit.org/show_bug.cgi?id=68833
+
+ Reviewed by Alexey Proskuryakov.
+
+ Test: http/tests/eventsource/eventsource-eof.html
+
+ * page/EventSource.cpp:
+ (WebCore::EventSource::didFinishLoading):
+ (WebCore::EventSource::parseEventStreamLine):
+ * page/EventSource.h:
+
2011-12-21 Andreas Kling <kl...@webkit.org>
Automate elements' registration as document namedItem/extraNamedItem.
Modified: trunk/Source/WebCore/page/EventSource.cpp (103473 => 103474)
--- trunk/Source/WebCore/page/EventSource.cpp 2011-12-22 00:25:18 UTC (rev 103473)
+++ trunk/Source/WebCore/page/EventSource.cpp 2011-12-22 00:37:11 UTC (rev 103474)
@@ -250,8 +250,13 @@
ASSERT(m_requestInFlight);
if (m_receiveBuf.size() > 0 || m_data.size() > 0) {
- append(m_receiveBuf, "\n\n");
parseEventStream();
+
+ // Discard everything that has not been dispatched by now.
+ m_receiveBuf.clear();
+ m_data.clear();
+ m_eventName = "";
+ m_currentlyParsedEventId = String();
}
networkRequestEnded();
}
@@ -322,6 +327,10 @@
if (!lineLength) {
if (!m_data.isEmpty()) {
m_data.removeLast();
+ if (!m_currentlyParsedEventId.isNull()) {
+ m_lastEventId.swap(m_currentlyParsedEventId);
+ m_currentlyParsedEventId = String();
+ }
dispatchEvent(createMessageEvent());
}
if (!m_eventName.isEmpty())
@@ -347,7 +356,7 @@
} else if (field == "event")
m_eventName = valueLength ? String(&m_receiveBuf[bufPos], valueLength) : "";
else if (field == "id")
- m_lastEventId = valueLength ? String(&m_receiveBuf[bufPos], valueLength) : "";
+ m_currentlyParsedEventId = valueLength ? String(&m_receiveBuf[bufPos], valueLength) : "";
else if (field == "retry") {
if (!valueLength)
m_reconnectDelay = defaultReconnectDelay;
Modified: trunk/Source/WebCore/page/EventSource.h (103473 => 103474)
--- trunk/Source/WebCore/page/EventSource.h 2011-12-22 00:25:18 UTC (rev 103473)
+++ trunk/Source/WebCore/page/EventSource.h 2011-12-22 00:37:11 UTC (rev 103474)
@@ -114,6 +114,7 @@
String m_eventName;
Vector<UChar> m_data;
+ String m_currentlyParsedEventId;
String m_lastEventId;
unsigned long long m_reconnectDelay;
String m_origin;