Skip to content

Commit 71c6f99

Browse files
committed
bug symfony#23426 Fixed HttpOnly flag when using Cookie::fromString() (Toflar)
This PR was merged into the 3.3 branch. Discussion ---------- Fixed HttpOnly flag when using Cookie::fromString() | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#23424 | License | MIT | Doc PR | - Using `Cookie::fromString()` should not set the `HttpOnly` flag to `true` by default. This is a factory method and it should create an instance of `Cookie` that represents exactly what the string contains. Commits ------- 73187d0 Preserve HttpOnly value when deserializing a header
2 parents 48bb195 + 73187d0 commit 71c6f99

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/Symfony/Component/HttpFoundation/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static function fromString($cookie, $decode = false)
4646
'path' => '/',
4747
'domain' => null,
4848
'secure' => false,
49-
'httponly' => true,
49+
'httponly' => false,
5050
'raw' => !$decode,
5151
'samesite' => null,
5252
);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ public function testFromString()
200200
$this->assertEquals(new Cookie('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, true), $cookie);
201201

202202
$cookie = Cookie::fromString('foo=bar', true);
203-
$this->assertEquals(new Cookie('foo', 'bar'), $cookie);
203+
$this->assertEquals(new Cookie('foo', 'bar', 0, '/', null, false, false), $cookie);
204+
}
205+
206+
public function testFromStringWithHttpOnly()
207+
{
208+
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
209+
$this->assertTrue($cookie->isHttpOnly());
210+
211+
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure');
212+
$this->assertFalse($cookie->isHttpOnly());
204213
}
205214
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ public function testSetCookieHeader()
241241
{
242242
$bag = new ResponseHeaderBag();
243243
$bag->set('set-cookie', 'foo=bar');
244-
$this->assertEquals(array(new Cookie('foo', 'bar', 0, '/', null, false, true, true)), $bag->getCookies());
244+
$this->assertEquals(array(new Cookie('foo', 'bar', 0, '/', null, false, false, true)), $bag->getCookies());
245245

246246
$bag->set('set-cookie', 'foo2=bar2', false);
247247
$this->assertEquals(array(
248-
new Cookie('foo', 'bar', 0, '/', null, false, true, true),
249-
new Cookie('foo2', 'bar2', 0, '/', null, false, true, true),
248+
new Cookie('foo', 'bar', 0, '/', null, false, false, true),
249+
new Cookie('foo2', 'bar2', 0, '/', null, false, false, true),
250250
), $bag->getCookies());
251251

252252
$bag->remove('set-cookie');

0 commit comments

Comments
 (0)