Skip to content

feat: update CookieInterface::EXPIRES_FORMAT to use date format per RFC 7231 #9563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: 4.7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion system/Cookie/CookieInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface CookieInterface
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date
* @see https://tools.ietf.org/html/rfc7231#section-7.1.1.2
*/
public const EXPIRES_FORMAT = 'D, d-M-Y H:i:s T';
public const EXPIRES_FORMAT = DATE_RFC7231;

/**
* Returns a unique identifier for the cookie consisting
Expand Down
8 changes: 4 additions & 4 deletions tests/system/Cookie/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ public function testExpirationTime(): void
// expires => 0
$cookie = new Cookie('test', 'value');
$this->assertSame(0, $cookie->getExpiresTimestamp());
$this->assertSame('Thu, 01-Jan-1970 00:00:00 GMT', $cookie->getExpiresString());
$this->assertSame('Thu, 01 Jan 1970 00:00:00 GMT', $cookie->getExpiresString());
$this->assertTrue($cookie->isExpired());
$this->assertSame(0, $cookie->getMaxAge());

$date = new DateTimeImmutable('2021-01-10 00:00:00 GMT', new DateTimeZone('UTC'));
$cookie = new Cookie('test', 'value', ['expires' => $date]);
$this->assertSame((int) $date->format('U'), $cookie->getExpiresTimestamp());
$this->assertSame('Sun, 10-Jan-2021 00:00:00 GMT', $cookie->getExpiresString());
$this->assertSame('Sun, 10 Jan 2021 00:00:00 GMT', $cookie->getExpiresString());
}

/**
Expand Down Expand Up @@ -272,15 +272,15 @@ public function testStringCastingOfCookies(): void
$a->toHeaderString(),
);
$this->assertSame(
"cookie=monster; Expires=Sun, 14-Feb-2021 00:00:00 GMT; Max-Age={$max}; Path=/web; Domain=localhost; HttpOnly; SameSite=Lax",
"cookie=monster; Expires=Sun, 14 Feb 2021 00:00:00 GMT; Max-Age={$max}; Path=/web; Domain=localhost; HttpOnly; SameSite=Lax",
(string) $b,
);
$this->assertSame(
'cookie=lover; Path=/; Secure; SameSite=Strict',
(string) $c,
);
$this->assertSame(
'cookie=deleted; Expires=Thu, 01-Jan-1970 00:00:00 GMT; Max-Age=0; Path=/; HttpOnly; SameSite=Lax',
'cookie=deleted; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0; Path=/; HttpOnly; SameSite=Lax',
(string) $d,
);

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.7.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ Message Changes
Changes
*******

- **Cookie:** The ``CookieInterface::EXPIRES_FORMAT`` has been changed to ``D, d M Y H:i:s \G\M\T`` to follow the recommended format in RFC 7231.

************
Deprecations
************
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/libraries/cookies/004.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$cookie->getPrefix(); // '__Secure-'
$cookie->getPrefixedName(); // '__Secure-remember_token'
$cookie->getExpiresTimestamp(); // UNIX timestamp
$cookie->getExpiresString(); // 'Fri, 14-Feb-2025 00:00:00 GMT'
$cookie->getExpiresString(); // 'Fri, 14 Feb 2025 00:00:00 GMT'
$cookie->isExpired(); // false
$cookie->getMaxAge(); // the difference from time() to expires
$cookie->isRaw(); // false
Expand Down
Loading