From 5e899cd2a78d19b759a01e4974182a51f5fbc0ba Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Tue, 13 Dec 2016 18:58:15 +0000 Subject: [PATCH] [HttpFoundation] Fix cookie to string conversion for raw cookies --- src/Symfony/Component/HttpFoundation/Cookie.php | 12 ++++++------ .../Component/HttpFoundation/Tests/CookieTest.php | 6 ++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/Cookie.php b/src/Symfony/Component/HttpFoundation/Cookie.php index 67e20dd501..6513421dc3 100644 --- a/src/Symfony/Component/HttpFoundation/Cookie.php +++ b/src/Symfony/Component/HttpFoundation/Cookie.php @@ -80,20 +80,20 @@ class Cookie */ public function __toString() { - $str = urlencode($this->getName()).'='; + $str = ($this->isRaw() ? $this->getName() : urlencode($this->getName())).'='; if ('' === (string) $this->getValue()) { $str .= 'deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001); } else { - $str .= urlencode($this->getValue()); + $str .= $this->isRaw() ? $this->getValue() : urlencode($this->getValue()); if ($this->getExpiresTime() !== 0) { $str .= '; expires='.gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime()); } } - if ($this->path) { - $str .= '; path='.$this->path; + if ($this->getPath()) { + $str .= '; path='.$this->getPath(); } if ($this->getDomain()) { @@ -124,7 +124,7 @@ class Cookie /** * Gets the value of the cookie. * - * @return string + * @return string|null */ public function getValue() { @@ -134,7 +134,7 @@ class Cookie /** * Gets the domain that the cookie is available to. * - * @return string + * @return string|null */ public function getDomain() { diff --git a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php index 9134c1570c..bcc0e014f3 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php @@ -154,10 +154,12 @@ class CookieTest extends \PHPUnit_Framework_TestCase public function testRawCookie() { - $cookie = new Cookie('foo', 'bar', 3600, '/', '.myfoodomain.com', false, true); + $cookie = new Cookie('foo', 'b a r', 0, '/', null, false, false); $this->assertFalse($cookie->isRaw()); + $this->assertEquals('foo=b+a+r; path=/', (string) $cookie); - $cookie = new Cookie('foo', 'bar', 3600, '/', '.myfoodomain.com', false, true, true); + $cookie = new Cookie('foo', 'b+a+r', 0, '/', null, false, false, true); $this->assertTrue($cookie->isRaw()); + $this->assertEquals('foo=b+a+r; path=/', (string) $cookie); } }