Skip to content

Commit

Permalink
Merge pull request #3 from bag2php/fix/remove-cookie
Browse files Browse the repository at this point in the history
Fix SetCookie to remove cookie entry
  • Loading branch information
zonuexe committed Aug 5, 2022
2 parents 5c7b895 + c210d75 commit 5d2ad7d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/SetCookie.php
Expand Up @@ -172,11 +172,9 @@ public static function assertOptions(array $options): void
*/
public function compileHeaderLine(int $now): string
{
if ($this->value === '') {
return $this->compileRemoveHeaderLine();
}

$line = "{$this->name}=" . $this->encodeValue($this->value);
$line = $this->value === ''
? $this->compileRemoveHeaderLine()
: "{$this->name}=" . $this->encodeValue($this->value);

$expires = $this->options['expires'] ?? 0;
if ($expires > 0) {
Expand Down Expand Up @@ -217,7 +215,7 @@ public function compileHeaderLine(int $now): string

public function compileRemoveHeaderLine(): string
{
return "";
return "{$this->name}=";
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/SetCookieTest.php
Expand Up @@ -142,6 +142,21 @@ public function cookieProvider(): array
],
'expected_line' => 'Expires=is%20past.; Expires=Sun, 12 Jan 2020 07:25:55 GMT; Max-Age=0',
],
[
'name' => 'Remove',
'value' => '',
'options' => [
'expires' => self::NOW - 1,
],
'expected_array' => [
'name' => 'Remove',
'value' => '',
'options' => [
'expires' => self::NOW - 1,
],
],
'expected_line' => 'Remove=; Expires=Sun, 12 Jan 2020 07:25:55 GMT; Max-Age=0',
],
];
}

Expand Down

0 comments on commit 5d2ad7d

Please sign in to comment.