8000 [HttpFoundation] Fix cookie to string conversion for raw cookies · symfony/symfony@5e899cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e899cd

Browse files
ro0NLfabpot
authored andcommitted
[HttpFoundation] Fix cookie to string conversion for raw cookies
1 parent 298452d commit 5e899cd

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/Symfony/Component/HttpFoundation/Cookie.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom
8080
*/
8181
public function __toString()
8282
{
83-
$str = urlencode($this->getName()).'=';
83+
$str = ($this->isRaw() ? $this->getName() : urlencode($this->getName())).'=';
8484

8585
if ('' === (string) $this->getValue()) {
8686
$str .= 'deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001);
8787
} else {
88-
$str .= urlencode($this->getValue());
88+
$str .= $this->isRaw() ? $this->getValue() : urlencode($this->getValue());
8989

9090
if ($this->getExpiresTime() !== 0) {
9191
$str .= '; expires='.gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime());
9292
}
9393
}
9494

95-
if ($this->path) {
96-
$str .= '; path='.$this->path;
95+
if ($this->getPath()) {
96+
$str .= '; path='.$this->getPath();
9797
}
9898

9999
if ($this->getDomain()) {
@@ -124,7 +124,7 @@ public function getName()
124124
/**
125125
* Gets the value of the cookie.
126126
*
127-
* @return string
127+
* @return string|null
128128
*/
129129
public function getValue()
130130
{
@@ -134,7 +134,7 @@ public function getValue()
134134
/**
135135
* Gets the domain that the cookie is available to.
136136
*
137-
* @return string
137+
* @return string|null
138138
*/
139139
public function getDomain()
140140
{

src/Symfony/Component/HttpFoundation/Tests/CookieTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,12 @@ public function testToString()
154154

155155
public function testRawCookie()
156156
{
157-
$cookie = new Cookie('foo', 'bar', 3600, '/', '.myfoodomain.com', false, true);
157+
$cookie = new Cookie('foo', 'b a r', 0, '/', null, false, false);
158158
$this->assertFalse($cookie->isRaw());
159+
$this->assertEquals('foo=b+a+r; path=/', (string) $cookie);
159160

160-
$cookie = new Cookie('foo', 'bar', 3600, '/', '.myfoodomain.com', false, true, true);
161+
$cookie = new Cookie('foo', 'b+a+r', 0, '/', null, false, false, true);
161162
$this->assertTrue($cookie->isRaw());
163+
$this->assertEquals('foo=b+a+r; path=/', (string) $cookie);
162164
}
163165
}

0 commit comments

Comments
 (0)
0