Skip to content

Commit bdea420

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: fix syntax for PHP 7.2 [Security] Fix Danish translations [DomCrawler] Encode html entities only if nessecary [Serializer] Ignore when using #[Ignore] on a non-accessor [Filesystem] Strengthen the check of file permissions in `dumpFile` [Serializer] Fix XML scalar to object denormalization [HttpClient][EventSourceHttpClient] Fix consuming SSEs with \r\n separator
2 parents 6a46c0e + ab3240a commit bdea420

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

EventSourceHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function request(string $method, string $url, array $options = []): Respo
121121
return;
122122
}
123123

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

127127
if ($chunk->isLast()) {

Tests/EventSourceHttpClientTest.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@
2727
*/
2828
class EventSourceHttpClientTest extends TestCase
2929
{
30-
public function testGetServerSentEvents()
30+
/**
31+
* @testWith ["\n"]
32+
* ["\r"]
33+
* ["\r\n"]
34+
*/
35+
public function testGetServerSentEvents(string $sep)
3136
{
32-
$data = <<<TXT
37+
$rawData = <<<TXT
3338
event: builderror
3439
id: 46
3540
data: {"foo": "bar"}
@@ -58,6 +63,7 @@ public function testGetServerSentEvents()
5863
id: 60
5964
data
6065
TXT;
66+
$data = str_replace("\n", $sep, $rawData);
6167

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

8490
$expected = [
8591
new FirstChunk(),
86-
new ServerSentEvent("event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n"),
87-
new ServerSentEvent("event: reload\nid: 47\ndata: {}\n\n"),
88-
new ServerSentEvent("event: reload\nid: 48\ndata: {}\n\n"),
89-
new ServerSentEvent("data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n"),
90-
new ServerSentEvent("id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n"),
92+
new ServerSentEvent(str_replace("\n", $sep, "event: builderror\nid: 46\ndata: {\"foo\": \"bar\"}\n\n")),
93+
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 47\ndata: {}\n\n")),
94+
new ServerSentEvent(str_replace("\n", $sep, "event: reload\nid: 48\ndata: {}\n\n")),
95+
new ServerSentEvent(str_replace("\n", $sep, "data: test\ndata:test\nid: 49\nevent: testEvent\n\n\n")),
96+
new ServerSentEvent(str_replace("\n", $sep, "id: 50\ndata: <tag>\ndata\ndata: <foo />\ndata\ndata: </tag>\n\n")),
9197
];
9298
$i = 0;
9399

0 commit comments

Comments
 (0)