Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[EventSource] Stop allowing trailing junk when parsing retry delay
https://bugs.webkit.org/show_bug.cgi?id=243227

Reviewed by Darin Adler.

Stop allowing trailing junk when parsing retry delay for EventSource:
- https://html.spec.whatwg.org/multipage/server-sent-events.html#processField

This aligns our behavior with Blink and Gecko.

* LayoutTests/imported/w3c/web-platform-tests/eventsource/format-field-retry-bogus.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/eventsource/format-field-retry-bogus.any.worker-expected.txt:
* Source/WebCore/page/EventSource.cpp:
(WebCore::EventSource::parseEventStreamLine):

Canonical link: https://commits.webkit.org/252885@main
  • Loading branch information
cdumez committed Jul 27, 2022
1 parent a6e626a commit 8d4846a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
@@ -0,0 +1,3 @@

PASS EventSource: "retry" field (bogus)

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -0,0 +1,19 @@
// META: title=EventSource: "retry" field (bogus)
var test = async_test()
test.step(function() {
var timeoutms = 1000,
source = new EventSource("resources/message.py?message=retry%3A1000%0Aretry%3A5000x%0Adata%3Ax"),
opened = 0
source.onopen = function() {
test.step(function() {
if(opened == 0) {
opened = new Date().getTime()
} else {
var diff = (new Date().getTime()) - opened
assert_true(Math.abs(1 - diff / timeoutms) < 0.25) // allow 25% difference
this.close();
test.done()
}
}, this)
}
})
@@ -0,0 +1,3 @@

PASS EventSource: "retry" field (bogus)

@@ -0,0 +1 @@
<!-- This file is required for WebKit test infrastructure to run the templated test -->
@@ -1,3 +1,3 @@

FAIL EventSource: "retry" field (bogus) assert_true: expected true got false
PASS EventSource: "retry" field (bogus)

@@ -1,3 +1,3 @@

FAIL EventSource: "retry" field (bogus) assert_true: expected true got false
PASS EventSource: "retry" field (bogus)

4 changes: 1 addition & 3 deletions Source/WebCore/page/EventSource.cpp
Expand Up @@ -382,9 +382,7 @@ void EventSource::parseEventStreamLine(unsigned position, std::optional<unsigned
if (!valueLength)
m_reconnectDelay = defaultReconnectDelay;
else {
// FIXME: Do we really want to ignore trailing junk here?
// FIXME: When we can't parse the value, should we really leave m_reconnectDelay alone? Shouldn't we set it to defaultReconnectDelay?
if (auto reconnectDelay = parseIntegerAllowingTrailingJunk<uint64_t>({ &m_receiveBuffer[position], valueLength }))
if (auto reconnectDelay = parseInteger<uint64_t>({ &m_receiveBuffer[position], valueLength }))
m_reconnectDelay = *reconnectDelay;
}
}
Expand Down

0 comments on commit 8d4846a

Please sign in to comment.