Skip to content
This repository has been archived by the owner on Nov 15, 2017. It is now read-only.

Commit

Permalink
Do not alter options object in $.removeCookie (consider that a refere…
Browse files Browse the repository at this point in the history
…nce may have been passed), closes #175
  • Loading branch information
carhartl committed Mar 29, 2013
1 parent 0b9c6ca commit 047d82f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion jquery.cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@

$.removeCookie = function (key, options) {
if ($.cookie(key) !== undefined) {
$.cookie(key, '', $.extend(options, { expires: -1 }));
// Must not alter options, thus extending a fresh object...
$.cookie(key, '', $.extend({}, options, { expires: -1 }));

This comment has been minimized.

Copy link
@dharkness

dharkness Jun 4, 2013

The -1 expiry is turning the cookie into a session cookie. Yet I see v1.3.1 on the plugin registry is using "null" instead of empty string for the value and has no expiry. And it works at least in PhantomJS.

Is this a regression or old code or ... ?

This comment has been minimized.

Copy link
@FagnerMartinsBrack

FagnerMartinsBrack Jun 5, 2013

Collaborator

Expires -1 should mark the cookie for removal by the browser. Do you have a simplified example to show?

return true;
}
return false;
Expand Down
13 changes: 11 additions & 2 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ test('not existing with json = true', function () {

test('invalid JSON string with json = true', function () {
expect(1);


if ('JSON' in window) {
$.cookie.json = true;
Expand Down Expand Up @@ -121,7 +121,7 @@ test('call without arguments', function() {
foo: 'bar'
}, 'should return all cookies');
$.each($.cookie(), $.removeCookie);

$.cookie.json = true;
$.cookie('c', { foo: 'bar' });
deepEqual($.cookie(), {
Expand Down Expand Up @@ -244,6 +244,15 @@ test('with options', function() {
$.cookie = originalCookie;
});

test('passing options reference', function() {
expect(1);
var options = { path: '/' };
$.cookie('c', 'v', options);

$.removeCookie('c', options);
deepEqual(options, { path: '/' }, "won't alter options object");
});

test('[] used in name', function () {
expect(1);
$.cookie.raw = true;
Expand Down

0 comments on commit 047d82f

Please sign in to comment.