Skip to content

Commit e2ff187

Browse files
committed
Update cookie date time format
1 parent 474fc81 commit e2ff187

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

src/Symfony/Component/HttpFoundation/Cookie.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ public function __toString(): string
244244
$str .= '=';
245245

246246
if ('' === (string) $this->getValue()) {
247-
$str .= 'deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0';
247+
$str .= 'deleted; expires='.gmdate('D, d M Y H:i:s T', time() - 31536001).'; Max-Age=0';
248248
} else {
249249
$str .= $this->isRaw() ? $this->getValue() : rawurlencode($this->getValue());
250250

251251
if (0 !== $this->getExpiresTime()) {
252-
$str .= '; expires='.gmdate('D, d-M-Y H:i:s T', $this->getExpiresTime()).'; Max-Age='.$this->getMaxAge();
252+
$str .= '; expires='.gmdate('D, d M Y H:i:s T', $this->getExpiresTime()).'; Max-Age='.$this->getMaxAge();
253253
}
254254
}
255255

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -227,31 +227,31 @@ public function testCookieIsCleared()
227227

228228
public function testToString()
229229
{
230-
$expected = 'foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly';
231-
$cookie = Cookie::create('foo', 'bar', $expire = strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, false, null);
230+
$expected = 'foo=bar; expires=Fri, 20 May 2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly';
231+
$cookie = Cookie::create('foo', 'bar', $expire = strtotime('Fri, 20 May 2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, false, null);
232232
$this->assertEquals($expected, (string) $cookie, '->__toString() returns string representation of the cookie');
233233

234234
$cookie = Cookie::create('foo')
235235
->withValue('bar')
236-
->withExpires(strtotime('Fri, 20-May-2011 15:25:52 GMT'))
236+
->withExpires(strtotime('Fri, 20 May 2011 15:25:52 GMT'))
237237
->withDomain('.myfoodomain.com')
238238
->withSecure(true)
239239
->withSameSite(null);
240240
$this->assertEquals($expected, (string) $cookie, '->__toString() returns string representation of the cookie');
241241

242-
$expected = 'foo=bar%20with%20white%20spaces; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly';
243-
$cookie = Cookie::create('foo', 'bar with white spaces', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, false, null);
242+
$expected = 'foo=bar%20with%20white%20spaces; expires=Fri, 20 May 2011 15:25:52 GMT; Max-Age=0; path=/; domain=.myfoodomain.com; secure; httponly';
243+
$cookie = Cookie::create('foo', 'bar with white spaces', strtotime('Fri, 20 May 2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, false, null);
244244
$this->assertEquals($expected, (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');
245245

246246
$cookie = Cookie::create('foo')
247247
->withValue('bar with white spaces')
248-
->withExpires(strtotime('Fri, 20-May-2011 15:25:52 GMT'))
248+
->withExpires(strtotime('Fri, 20 May 2011 15:25:52 GMT'))
249249
->withDomain('.myfoodomain.com')
250250
->withSecure(true)
251251
->withSameSite(null);
252252
$this->assertEquals($expected, (string) $cookie, '->__toString() encodes the value of the cookie according to RFC 3986 (white space = %20)');
253253

254-
$expected = 'foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', $expire = time() - 31536001).'; Max-Age=0; path=/admin/; domain=.myfoodomain.com; httponly';
254+
$expected = 'foo=deleted; expires='.gmdate('D, d M Y H:i:s T', $expire = time() - 31536001).'; Max-Age=0; path=/admin/; domain=.myfoodomain.com; httponly';
255255
$cookie = Cookie::create('foo', null, 1, '/admin/', '.myfoodomain.com', false, true, false, null);
256256
$this->assertEquals($expected, (string) $cookie, '->__toString() returns string representation of a cleared cookie if value is NULL');
257257

@@ -307,28 +307,28 @@ public function testGetMaxAge()
307307

308308
public function testFromString()
309309
{
310-
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
311-
$this->assertEquals(Cookie::create('foo', 'bar', strtotime('Fri, 20-May-2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, true, null), $cookie);
310+
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20 May 2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
311+
$this->assertEquals(Cookie::create('foo', 'bar', strtotime('Fri, 20 May 2011 15:25:52 GMT'), '/', '.myfoodomain.com', true, true, true, null), $cookie);
312312

313313
$cookie = Cookie::fromString('foo=bar', true);
314314
$this->assertEquals(Cookie::create('foo', 'bar', 0, '/', null, false, false, false, null), $cookie);
315315

316316
$cookie = Cookie::fromString('foo', true);
317317
$this->assertEquals(Cookie::create('foo', null, 0, '/', null, false, false, false, null), $cookie);
318318

319-
$cookie = Cookie::fromString('foo_cookie=foo=1&bar=2&baz=3; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/');
320-
$this->assertEquals(Cookie::create('foo_cookie', 'foo=1&bar=2&baz=3', strtotime('Tue, 22-Sep-2020 06:27:09 GMT'), '/', null, false, false, true, null), $cookie);
319+
$cookie = Cookie::fromString('foo_cookie=foo=1&bar=2&baz=3; expires=Tue, 22 Sep 2020 06:27:09 GMT; path=/');
320+
$this->assertEquals(Cookie::create('foo_cookie', 'foo=1&bar=2&baz=3', strtotime('Tue, 22 Sep 2020 06:27:09 GMT'), '/', null, false, false, true, null), $cookie);
321321

322-
$cookie = Cookie::fromString('foo_cookie=foo==; expires=Tue, 22-Sep-2020 06:27:09 GMT; path=/');
323-
$this->assertEquals(Cookie::create('foo_cookie', 'foo==', strtotime('Tue, 22-Sep-2020 06:27:09 GMT'), '/', null, false, false, true, null), $cookie);
322+
$cookie = Cookie::fromString('foo_cookie=foo==; expires=Tue, 22 Sep 2020 06:27:09 GMT; path=/');
323+
$this->assertEquals(Cookie::create('foo_cookie', 'foo==', strtotime('Tue, 22 Sep 2020 06:27:09 GMT'), '/', null, false, false, true, null), $cookie);
324324
}
325325

326326
public function testFromStringWithHttpOnly()
327327
{
328-
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
328+
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20 May 2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure; httponly');
329329
$this->assertTrue($cookie->isHttpOnly());
330330

331-
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure');
331+
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20 May 2011 15:25:52 GMT; path=/; domain=.myfoodomain.com; secure');
332332
$this->assertFalse($cookie->isHttpOnly());
333333
}
334334

@@ -361,15 +361,15 @@ public function testSetSecureDefault()
361361

362362
public function testMaxAge()
363363
{
364-
$futureDateOneHour = gmdate('D, d-M-Y H:i:s T', time() + 3600);
364+
$futureDateOneHour = gmdate('D, d M Y H:i:s T', time() + 3600);
365365

366366
$cookie = Cookie::fromString('foo=bar; Max-Age=3600; path=/');
367367
$this->assertEquals('foo=bar; expires='.$futureDateOneHour.'; Max-Age=3600; path=/', $cookie->__toString());
368368

369369
$cookie = Cookie::fromString('foo=bar; expires='.$futureDateOneHour.'; Max-Age=3600; path=/');
370370
$this->assertEquals('foo=bar; expires='.$futureDateOneHour.'; Max-Age=3600; path=/', $cookie->__toString());
371371

372-
$futureDateHalfHour = gmdate('D, d-M-Y H:i:s T', time() + 1800);
372+
$futureDateHalfHour = gmdate('D, d M Y H:i:s T', time() + 1800);
373373

374374
// Max-Age value takes precedence before expires
375375
$cookie = Cookie::fromString('foo=bar; expires='.$futureDateHalfHour.'; Max-Age=3600; path=/');
@@ -378,13 +378,13 @@ public function testMaxAge()
378378

379379
public function testExpiredWithMaxAge()
380380
{
381-
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/');
382-
$this->assertEquals('foo=bar; expires=Fri, 20-May-2011 15:25:52 GMT; Max-Age=0; path=/', $cookie->__toString());
381+
$cookie = Cookie::fromString('foo=bar; expires=Fri, 20 May 2011 15:25:52 GMT; Max-Age=0; path=/');
382+
$this->assertEquals('foo=bar; expires=Fri, 20 May 2011 15:25:52 GMT; Max-Age=0; path=/', $cookie->__toString());
383383

384384
$futureDate = gmdate('D, d-M-Y H:i:s T', time() + 864000);
385385

386386
$cookie = Cookie::fromString('foo=bar; expires='.$futureDate.'; Max-Age=0; path=/');
387387
$this->assertEquals(time(), $cookie->getExpiresTime());
388-
$this->assertEquals('foo=bar; expires='.gmdate('D, d-M-Y H:i:s T', $cookie->getExpiresTime()).'; Max-Age=0; path=/', $cookie->__toString());
388+
$this->assertEquals('foo=bar; expires='.gmdate('D, d M Y H:i:s T', $cookie->getExpiresTime()).'; Max-Age=0; path=/', $cookie->__toString());
389389
}
390390
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function testToStringIncludesCookieHeaders()
116116

117117
$bag->clearCookie('foo');
118118

119-
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; httponly', $bag);
119+
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d M Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; httponly', $bag);
120120
}
121121

122122
public function testClearCookieSecureNotHttpOnly()
@@ -125,15 +125,15 @@ public function testClearCookieSecureNotHttpOnly()
125125

126126
$bag->clearCookie('foo', '/', null, true, false);
127127

128-
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure', $bag);
128+
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d M Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure', $bag);
129129
}
130130

131131
public function testClearCookieSamesite()
132132
{
133133
$bag = new ResponseHeaderBag([]);
134134

135135
$bag->clearCookie('foo', '/', null, true, false, 'none');
136-
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d-M-Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure; samesite=none', $bag);
136+
$this->assertSetCookieHeader('foo=deleted; expires='.gmdate('D, d M Y H:i:s T', time() - 31536001).'; Max-Age=0; path=/; secure; samesite=none', $bag);
137137
}
138138

139139
public function testReplace()

0 commit comments

Comments
 (0)