Merge pull request #9703 from cakephp/issue-9698

Fix HttpSocket emitting errors when nameless cookies are encountered.
This commit is contained in:
Mark Story 2016-11-04 21:51:36 -04:00 committed by GitHub
commit 0dcb5ffbfe
2 changed files with 21 additions and 8 deletions

View file

@ -319,7 +319,11 @@ class HttpSocketResponse implements ArrayAccess {
$parts = preg_split('/\;[ \t]*/', $cookie);
}
list($name, $value) = explode('=', array_shift($parts), 2);
$nameParts = explode('=', array_shift($parts), 2);
if (count($nameParts) < 2) {
$nameParts = array('', $nameParts[0]);
}
list($name, $value) = $nameParts;
$cookies[$name] = compact('value');
foreach ($parts as $part) {

View file

@ -480,7 +480,9 @@ class HttpResponseTest extends CakeTestCase {
'Set-Cookie' => array(
'foo=bar',
'people=jim,jack,johnny";";Path=/accounts',
'google=not=nice'
'google=not=nice',
'1271; domain=.example.com; expires=Fri, 04-Nov-2016 12:50:26 GMT; path=/',
'cakephp=great; Secure'
),
'Transfer-Encoding' => 'chunked',
'Date' => 'Sun, 18 Nov 2007 18:57:42 GMT',
@ -496,17 +498,24 @@ class HttpResponseTest extends CakeTestCase {
),
'google' => array(
'value' => 'not=nice',
),
'' => array(
'value' => '1271',
'domain' => '.example.com',
'expires' => 'Fri, 04-Nov-2016 12:50:26 GMT',
'path' => '/'
),
'cakephp' => array(
'value' => 'great',
'secure' => true,
)
);
$this->assertEquals($expected, $cookies);
$header['Set-Cookie'][] = 'cakephp=great; Secure';
$expected['cakephp'] = array('value' => 'great', 'secure' => true);
$cookies = $this->HttpResponse->parseCookies($header);
$this->assertEquals($expected, $cookies);
$header['Set-Cookie'] = 'foo=bar';
unset($expected['people'], $expected['cakephp'], $expected['google']);
$expected = array(
'foo' => array('value' => 'bar')
);
$cookies = $this->HttpResponse->parseCookies($header);
$this->assertEquals($expected, $cookies);
}