Skip to content

Commit

Permalink
Fix SetCookie::fromString MaxAge deprecation warning and skip inval…
Browse files Browse the repository at this point in the history
…id MaxAge values
  • Loading branch information
GrahamCampbell committed May 15, 2023
1 parent 4019c94 commit 847d9ab
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Cookie/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ public static function fromString(string $cookie): self
} else {
foreach (\array_keys(self::$defaults) as $search) {
if (!\strcasecmp($search, $key)) {
$data[$search] = $value;
if ($search === 'Max-Age') {
if (is_numeric($value)) {
$data[$search] = (int) $value;
}
} else {
$data[$search] = $value;
}
continue 2;
}
}
Expand Down
30 changes: 30 additions & 0 deletions tests/Cookie/SetCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,36 @@ public function cookieParserDataProvider()
'SameSite' => 'None',
],
],
[
'SESS3a6f27284c4d8b34b6f4ff98cb87703e=Ts-5YeSyvOCMS%2CzkEb9eDfW4C4ZNFOcRYdu-3JpEAXIm58aH; expires=Wed, 07-Jun-2023 15:56:35 GMT; Max-Age=2000000; path=/; domain=.example.com; HttpOnly; SameSite=Lax',
[
'Name' => 'SESS3a6f27284c4d8b34b6f4ff98cb87703e',
'Value' => 'Ts-5YeSyvOCMS%2CzkEb9eDfW4C4ZNFOcRYdu-3JpEAXIm58aH',
'Domain' => '.example.com',
'Path' => '/',
'Expires' => 'Wed, 07-Jun-2023 15:56:35 GMT',
'Secure' => false,
'Discard' => false,
'Max-Age' => 2000000,
'HttpOnly' => true,
'SameSite' => 'Lax',
],
],
[
'SESS3a6f27284c4d8b34b6f4ff98cb87703e=Ts-5YeSyvOCMS%2CzkEb9eDfW4C4ZNFOcRYdu-3JpEAXIm58aH; expires=Wed, 07-Jun-2023 15:56:35 GMT; Max-Age=qwerty; path=/; domain=.example.com; HttpOnly; SameSite=Lax',
[
'Name' => 'SESS3a6f27284c4d8b34b6f4ff98cb87703e',
'Value' => 'Ts-5YeSyvOCMS%2CzkEb9eDfW4C4ZNFOcRYdu-3JpEAXIm58aH',
'Domain' => '.example.com',
'Path' => '/',
'Expires' => 'Wed, 07-Jun-2023 15:56:35 GMT',
'Secure' => false,
'Discard' => false,
'Max-Age' => null,
'HttpOnly' => true,
'SameSite' => 'Lax',
],
],
];
}

Expand Down

0 comments on commit 847d9ab

Please sign in to comment.