Skip to content
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

fix. delete_cookite can't delete alreday set Cookie #2709

Merged
merged 2 commits into from
Apr 20, 2020
Merged
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
8 changes: 7 additions & 1 deletion system/HTTP/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ public function deleteCookie(string $name = '', string $domain = '', string $pat

$name = $prefix . $name;

$cookieHasFlag = false;
foreach ($this->cookies as &$cookie)
{
if ($cookie['name'] === $name)
Expand All @@ -1000,11 +1001,16 @@ public function deleteCookie(string $name = '', string $domain = '', string $pat
}
$cookie['value'] = '';
$cookie['expires'] = '';

$cookieHasFlag = true;
break;
}
}

if (! $cookieHasFlag)
{
$this->setCookie($name, '', '', $domain, $path, $prefix);
}

return $this;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/system/Helpers/CookieHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,13 @@ public function testGetCookie()
$this->assertEquals(5, get_cookie('TEST'));
}

public function testDeleteCookieAfterLastSet()
{
delete_cookie($this->name);

$cookie = $this->response->getCookie($this->name);
// The cookie is set to be cleared when the request is sent....
$this->assertEquals('', $cookie['value']);
}

}