angular-cookie icon indicating copy to clipboard operation
angular-cookie copied to clipboard

.remove does not remove cookies set on specific paths.

Open p1100i opened this issue 10 years ago • 5 comments

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: /subpage/

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.

p1100i avatar Sep 02 '14 10:09 p1100i

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.

bbrown avatar Dec 04 '14 20:12 bbrown

Yes, this is not the behavior I expected :(

idoo avatar Mar 21 '15 13:03 idoo

.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.

ashish173 avatar May 23 '15 11:05 ashish173

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.

pascalwinter avatar Mar 16 '16 14:03 pascalwinter

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 ?

kaleemullah360 avatar Apr 28 '17 18:04 kaleemullah360