Skip to content

Commit

Permalink
Fix cookies being doubly encoded by ResponseEmitter.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markstory committed Oct 3, 2016
1 parent b597a0d commit 5c7bd52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Http/ResponseEmitter.php
Expand Up @@ -194,8 +194,8 @@ protected function emitCookies(array $cookies)

list($name, $value) = explode('=', array_shift($parts), 2);
$data = [
'name' => $name,
'value' => $value,
'name' => urldecode($name),
'value' => urldecode($value),
'expires' => 0,
'path' => '',
'domain' => '',
Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase/Http/ResponseEmitterTest.php
Expand Up @@ -75,6 +75,7 @@ public function testEmitResponseCookies()
->withAddedHeader('Set-Cookie', 'people=jim,jack,jonny";";Path=/accounts')
->withAddedHeader('Set-Cookie', 'google=not=nice;Path=/accounts; HttpOnly')
->withAddedHeader('Set-Cookie', 'a=b; Expires=Wed, 13 Jan 2021 22:23:01 GMT; Domain=www.example.com;')
->withAddedHeader('Set-Cookie', 'list%5B%5D=a%20b%20c')
->withHeader('Content-Type', 'text/plain');
$response->getBody()->write('ok');

Expand Down Expand Up @@ -125,6 +126,15 @@ public function testEmitResponseCookies()
'secure' => false,
'httponly' => false
],
[
'name' => 'list[]',
'value' => 'a b c',
'path' => '',
'expire' => 0,
'domain' => '',
'secure' => false,
'httponly' => false
],
];
$this->assertEquals($expected, $GLOBALS['mockedCookies']);
}
Expand Down

0 comments on commit 5c7bd52

Please sign in to comment.