Skip to content

Commit 047d82f

Browse files
committed
Do not alter options object in $.removeCookie (consider that a reference may have been passed), closes js-cookie#175
1 parent 0b9c6ca commit 047d82f

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎jquery.cookie.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585

8686
$.removeCookie = function (key, options) {
8787
if ($.cookie(key) !== undefined) {
88-
$.cookie(key, '', $.extend(options, { expires: -1 }));
88+
// Must not alter options, thus extending a fresh object...
89+
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
8990
return true;
9091
}
9192
return false;

‎test/tests.js‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ test('not existing with json = true', function () {
8484

8585
test('invalid JSON string with json = true', function () {
8686
expect(1);
87-
87+
8888

8989
if ('JSON' in window) {
9090
$.cookie.json = true;
@@ -121,7 +121,7 @@ test('call without arguments', function() {
121121
foo: 'bar'
122122
}, 'should return all cookies');
123123
$.each($.cookie(), $.removeCookie);
124-
124+
125125
$.cookie.json = true;
126126
$.cookie('c', { foo: 'bar' });
127127
deepEqual($.cookie(), {
@@ -244,6 +244,15 @@ test('with options', function() {
244244
$.cookie = originalCookie;
245245
});
246246

247+
test('passing options reference', function() {
248+
expect(1);
249+
var options = { path: '/' };
250+
$.cookie('c', 'v', options);
251+
252+
$.removeCookie('c', options);
253+
deepEqual(options, { path: '/' }, "won't alter options object");
254+
});
255+
247256
test('[] used in name', function () {
248257
expect(1);
249258
$.cookie.raw = true;

0 commit comments

Comments
 (0)