Skip to content

Commit

Permalink
Merge pull request #2709 from Instrye/patch-1
Browse files Browse the repository at this point in the history
fix. delete_cookite can't delete alreday set Cookie
  • Loading branch information
lonnieezell committed Apr 20, 2020
2 parents 7115d64 + 2e9adfa commit 0c4725d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
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']);
}

}

0 comments on commit 0c4725d

Please sign in to comment.