Skip to content

Commit cdce6a6

Browse files
Merge branch '3.1' into 3.2
* 3.1: [Security] Fix test [Validator] phpize default option values test for the Validator component to be present [Serializer] Fix MaxDepth annotation exceptions [DependencyInjection] Fix on-invalid attribute type in xsd [FrameworkBundle] Fix PHP form templates on translatable attributes [VarDumper] Fix dumping by-ref variadics [Validator] add Indonesian translation fixed CS [config] Fix issue when key removed and left value only [HttpFoundation] Fix cookie to string conversion for raw cookies [Console] fixed BC issue with static closures [Security] AbstractVoter method supportsAttribute gives false positive if attribute is zero (0)
2 parents 9963bc2 + 7837fe9 commit cdce6a6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

Cookie.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,20 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom
9191
*/
9292
public function __toString()
9393
{
94-
$str = urlencode($this->getName()).'=';
94+
$str = ($this->isRaw() ? $this->getName() : urlencode($this->getName())).'=';
9595

9696
if ('' === (string) $this->getValue()) {
9797
$str .= 'deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001);
9898
} else {
99-
$str .= urlencode($this->getValue());
99+
$str .= $this->isRaw() ? $this->getValue() : urlencode($this->getValue());
100100

101101
if ($this->getExpiresTime() !== 0) {
102102
$str .= '; expires='.gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime());
103103
}
104104
}
105105

106-
if ($this->path) {
107-
$str .= '; path='.$this->path;
106+
if ($this->getPath()) {
107+
$str .= '; path='.$this->getPath();
108108
}
109109

110110
if ($this->getDomain()) {
@@ -139,7 +139,7 @@ public function getName()
139139
/**
140140
* Gets the value of the cookie.
141141
*
142-
* @return string
142+
* @return string|null
143143
*/
144144
public function getValue()
145145
{
@@ -149,7 +149,7 @@ public function getValue()
149149
/**
150150
* Gets the domain that the cookie is available to.
151151
*
152-
* @return string
152+
* @return string|null
153153
*/
154154
public function getDomain()
155155
{

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)