Skip to content

Commit

Permalink
Fix deleteCookie() when prefix is defined. Fixes #3433
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsn committed Aug 1, 2020
1 parent 906026e commit bc125f5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions system/HTTP/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,12 +984,12 @@ public function deleteCookie(string $name = '', string $domain = '', string $pat
$prefix = $this->cookiePrefix;
}

$name = $prefix . $name;
$prefixedName = $prefix . $name;

$cookieHasFlag = false;
foreach ($this->cookies as &$cookie)
{
if ($cookie['name'] === $name)
if ($cookie['name'] === $prefixedName)
{
if (! empty($domain) && $cookie['domain'] !== $domain)
{
Expand Down
8 changes: 4 additions & 4 deletions tests/system/HTTP/ResponseCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function testCookieDelete()
$response->setCookie(['name' => 'bee', 'value' => 'bop', 'expire' => 1000]);
$response->deleteCookie('bee');
$cookie = $response->getCookie('bee');
$this->assertTrue($cookie['expires'] <= time(), $cookie['expires'] . ' should be less than ' . time());
$this->assertEquals($cookie['expires'], '', 'Expires should be an empty string');

// delete cookie with wrong prefix?
$config->cookiePrefix = 'mine';
Expand All @@ -210,7 +210,7 @@ public function testCookieDelete()
$this->assertFalse($cookie['expires'] <= time(), $cookie['expires'] . ' should be less than ' . time());
$response->deleteCookie('bee', '', '', 'mine');
$cookie = $response->getCookie('bee');
$this->assertTrue($cookie['expires'] <= time(), $cookie['expires'] . ' should be less than ' . time());
$this->assertEquals($cookie['expires'], '', 'Expires should be an empty string');

// delete cookie with wrong domain?
$config->cookieDomain = '.mine.com';
Expand All @@ -221,7 +221,7 @@ public function testCookieDelete()
$this->assertFalse($cookie['expires'] <= time(), $cookie['expires'] . ' should be less than ' . time());
$response->deleteCookie('bee', '.mine.com', '', '');
$cookie = $response->getCookie('bee');
$this->assertTrue($cookie['expires'] <= time(), $cookie['expires'] . ' should be less than ' . time());
$this->assertEquals($cookie['expires'], '', 'Expires should be an empty string');

// delete cookie with wrong path?
$config->cookiePath = '/whoknowswhere';
Expand All @@ -232,7 +232,7 @@ public function testCookieDelete()
$this->assertFalse($cookie['expires'] <= time(), $cookie['expires'] . ' should be less than ' . time());
$response->deleteCookie('bee', '', '/whoknowswhere', '');
$cookie = $response->getCookie('bee');
$this->assertTrue($cookie['expires'] <= time(), $cookie['expires'] . ' should be less than ' . time());
$this->assertEquals($cookie['expires'], '', 'Expires should be an empty string');
}

}

0 comments on commit bc125f5

Please sign in to comment.