Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/EventSourceHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function request(string $method, string $url, array $options = []): Respo
return;
}

$rx = '/((?:\r\n|[\r\n]){2,})/';
$rx = '/((?:\r\n){2,}|\r{2,}|\n{2,})/';
$content = $state->buffer.$chunk->getContent();

if ($chunk->isLast()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@
*/
class EventSourceHttpClientTest extends TestCase
{
public function testGetServerSentEvents()
/**
* @testWith ["\n"]
* ["\r"]
* ["\r\n"]
*/
public function testGetServerSentEvents(string $sep)
{
$data = <<<TXT
$data = str_replace("\n", $sep, <<<TXT
event: builderror
id: 46
data: {"foo": "bar"}
Expand Down Expand Up @@ -57,7 +62,7 @@ public function testGetServerSentEvents()

id: 60
data
TXT;
TXT);

$chunk = new DataChunk(0, $data);
$response = new MockResponse('', ['canceled' => false, 'http_method' => 'GET', 'url' => 'http://localhost:8080/events', 'response_headers' => ['content-type: text/event-stream']]);
Expand All @@ -83,11 +88,11 @@ public function testGetServerSentEvents()

$expected = [
new FirstChunk(),
new ServerSentEvent("event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n"),
new ServerSentEvent("event: reload\nid: 47\ndata: {}\n\n"),
new ServerSentEvent("event: reload\nid: 48\ndata: {}\n\n"),
new ServerSentEvent("data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n"),
new ServerSentEvent("id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n"),
new ServerSentEvent(str_replace("\n", $sep, "event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n")),
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 47\ndata: {}\n\n")),
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 48\ndata: {}\n\n")),
new ServerSentEvent(str_replace("\n", $sep, "data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n")),
new ServerSentEvent(str_replace("\n", $sep, "id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n")),
];
$i = 0;

Expand Down