Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f115d7a

Browse filesBrowse files
bug #48628 [HttpFoundation] Fix dumping array cookies (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpFoundation] Fix dumping array cookies | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48327 | License | MIT | Doc PR | - See https://www.php.net/manual/en/function.setcookie.php#refsect1-function.setcookie-notes Commits ------- 3cf4401 [HttpFoundation] Fix dumping array cookies
2 parents af562a7 + 3cf4401 commit f115d7a
Copy full SHA for f115d7a

File tree

2 files changed

+8
-2
lines changed
Filter options

2 files changed

+8
-2
lines changed

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ public function __toString()
522522
$cookies = [];
523523

524524
foreach ($this->cookies as $k => $v) {
525-
$cookies[] = $k.'='.$v;
525+
$cookies[] = \is_array($v) ? http_build_query([$k => $v], '', '; ', \PHP_QUERY_RFC3986) : "$k=$v";
526526
}
527527

528-
if (!empty($cookies)) {
528+
if ($cookies) {
529529
$cookieHeader = 'Cookie: '.implode('; ', $cookies)."\r\n";
530530
}
531531

‎src/Symfony/Component/HttpFoundation/Tests/RequestTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,12 @@ public function testToString()
17021702
$asString = (string) $request;
17031703

17041704
$this->assertStringContainsString('Cookie: Foo=Bar; Another=Cookie', $asString);
1705+
1706+
$request->cookies->set('foo.bar', [1, 2]);
1707+
1708+
$asString = (string) $request;
1709+
1710+
$this->assertStringContainsString('foo.bar%5B0%5D=1; foo.bar%5B1%5D=2', $asString);
17051711
}
17061712

17071713
public function testIsMethod()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.