diff --git a/system/Cookie/CookieInterface.php b/system/Cookie/CookieInterface.php index c848fa8884ec..8317617088cd 100644 --- a/system/Cookie/CookieInterface.php +++ b/system/Cookie/CookieInterface.php @@ -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 diff --git a/tests/system/Cookie/CookieTest.php b/tests/system/Cookie/CookieTest.php index e4421a8bc443..1438cfb9d513 100644 --- a/tests/system/Cookie/CookieTest.php +++ b/tests/system/Cookie/CookieTest.php @@ -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()); } /** @@ -272,7 +272,7 @@ 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( @@ -280,7 +280,7 @@ public function testStringCastingOfCookies(): void (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, ); diff --git a/user_guide_src/source/changelogs/v4.7.0.rst b/user_guide_src/source/changelogs/v4.7.0.rst index 7645847c59e9..a64f4245de05 100644 --- a/user_guide_src/source/changelogs/v4.7.0.rst +++ b/user_guide_src/source/changelogs/v4.7.0.rst @@ -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 ************ diff --git a/user_guide_src/source/libraries/cookies/004.php b/user_guide_src/source/libraries/cookies/004.php index e39854766db1..d68d97081713 100644 --- a/user_guide_src/source/libraries/cookies/004.php +++ b/user_guide_src/source/libraries/cookies/004.php @@ -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