Skip to content
Permalink
Browse files

Fix HttpSocket emitting errors when nameless cookies are encountered.

Refs #9698
  • Loading branch information...
markstory committed Nov 3, 2016
1 parent 7f0b073 commit 6a201696dde1419b882cd7eab3aa4370f43f5825
@@ -319,7 +319,11 @@ public function parseCookies($header) {
$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) {
@@ -480,7 +480,9 @@ public function testParseCookies() {
'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 @@ public function testParseCookies() {
),
'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);
}

0 comments on commit 6a20169

Please sign in to comment.
You can’t perform that action at this time.