From 6a201696dde1419b882cd7eab3aa4370f43f5825 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 3 Nov 2016 19:07:25 -0400 Subject: [PATCH 1/2] Fix HttpSocket emitting errors when nameless cookies are encountered. Refs #9698 --- lib/Cake/Network/Http/HttpSocketResponse.php | 6 ++++- .../Case/Network/Http/HttpResponseTest.php | 23 +++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/Cake/Network/Http/HttpSocketResponse.php b/lib/Cake/Network/Http/HttpSocketResponse.php index ceaaf3074..40bef3973 100644 --- a/lib/Cake/Network/Http/HttpSocketResponse.php +++ b/lib/Cake/Network/Http/HttpSocketResponse.php @@ -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) { diff --git a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php b/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php index 2fde8eb5e..5a22cc30c 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php @@ -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); } From 9d94487b237dabe3498cb339afbc46a9e98654b7 Mon Sep 17 00:00:00 2001 From: mark_story Date: Fri, 4 Nov 2016 09:31:05 -0400 Subject: [PATCH 2/2] Fix PHPCS Refs MATES-9698 --- lib/Cake/Test/Case/Network/Http/HttpResponseTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php b/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php index 5a22cc30c..4127dfc96 100644 --- a/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php +++ b/lib/Cake/Test/Case/Network/Http/HttpResponseTest.php @@ -499,7 +499,7 @@ class HttpResponseTest extends CakeTestCase { 'google' => array( 'value' => 'not=nice', ), - '' => array( + '' => array( 'value' => '1271', 'domain' => '.example.com', 'expires' => 'Fri, 04-Nov-2016 12:50:26 GMT',