Skip to content

Commit 5c7bd52

Browse files
committed
Fix cookies being doubly encoded by ResponseEmitter.
setcookie() applies URL encoding to the name & value. We need to remove a layer of encoding before calling setcookie(), as the Set-Cookie headers will have already been encoded and double encoded values break things like CookieComponent. Refs #9553
1 parent b597a0d commit 5c7bd52

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Http/ResponseEmitter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ protected function emitCookies(array $cookies)
194194

195195
list($name, $value) = explode('=', array_shift($parts), 2);
196196
$data = [
197-
'name' => $name,
198-
'value' => $value,
197+
'name' => urldecode($name),
198+
'value' => urldecode($value),
199199
'expires' => 0,
200200
'path' => '',
201201
'domain' => '',

tests/TestCase/Http/ResponseEmitterTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function testEmitResponseCookies()
7575
->withAddedHeader('Set-Cookie', 'people=jim,jack,jonny";";Path=/accounts')
7676
->withAddedHeader('Set-Cookie', 'google=not=nice;Path=/accounts; HttpOnly')
7777
->withAddedHeader('Set-Cookie', 'a=b; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Domain=www.example.com;')
78+
->withAddedHeader('Set-Cookie', 'list%5B%5D=a%20b%20c')
7879
->withHeader('Content-Type', 'text/plain');
7980
$response->getBody()->write('ok');
8081

@@ -125,6 +126,15 @@ public function testEmitResponseCookies()
125126
'secure' => false,
126127
'httponly' => false
127128
],
129+
[
130+
'name' => 'list[]',
131+
'value' => 'a b c',
132+
'path' => '',
133+
'expire' => 0,
134+
'domain' => '',
135+
'secure' => false,
136+
'httponly' => false
137+
],
128138
];
129139
$this->assertEquals($expected, $GLOBALS['mockedCookies']);
130140
}

0 commit comments

Comments
 (0)