angular-cookie
angular-cookie copied to clipboard
.remove does not remove cookies set on specific paths.
Not sure if this is a feature or a bug, however if I set a cookie with a specific path, .remove
does not have an effect on it, even doe' returning true
.
Reproduction steps:
Navigate on a domain with a subpage like:
ipCookie('x', 1, { path : '/subpage' });
ipCookie.remove('x') // returns true;
ipCookie('x') // returns 1, I was expecting it to be removed;
Extra info:
I know about the option ipCookie.remove('x', { path : '/subpage' })
however I was expecting from the return value of the remove above, to take effect on the /subpage
path as well.
Basically, it just sets the cookie's value to blank with an empty options object (by default) and then an expiration of -1. I extracted my set functionality into a service and then just pass into the set an empty string, so it'll use the same set of options exactly.
Yes, this is not the behavior I expected :(
.remove have got nothing to do with paths its not taken care of in the code.
cookieFun.remove = function (key, options) {
var hasCookie = cookieFun(key) !== undefined;
if (hasCookie) {
if (!options) {
options = {};
}
options.expires = -1;
cookieFun(key, '', options);
}
return hasCookie;
};
it basically fetches all the cookies and then sets empty on the key of the cookie which we want to delete.
I've noticed this issue as well. Because it is just setting the cookie value to to empty string, if the PATH and DOMAIN do not match the initial cookie, it will not be overwriting the correct cookie.
in angular 2 on calling remove all cookies only delete object cookies, the string cookies remain same. no values is over written and expiry is remain unchanged. I observe the issues right after specifying domain with loopback ip address in /etc/hosts
. any solution ?