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

Commit 4527b37

Browse files
committed
Fix removing cookies in sub paths
When trying to remove a cookie in a sub path (defined via path), we can't first try to read the cookie in a guard clause, it won't be readable and thus the removal was not even attempted. So I'm removing the guard clause entirely. On second thought its return value was also wrong anyway: when attempting to remove a non-existing cookie, after the removal it still doesn't exist and the removeCookie() should therefore return false. Closes #336.
1 parent 41b1bad commit 4527b37

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/jquery.cookie.js

-4
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@
106106
config.defaults = {};
107107

108108
$.removeCookie = function (key, options) {
109-
if ($.cookie(key) === undefined) {
110-
return false;
111-
}
112-
113109
// Must not alter options, thus extending a fresh object...
114110
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
115111
return !$.cookie(key);

test/tests.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ test('when sucessfully deleted', function () {
282282
strictEqual($.removeCookie('c'), true, 'returns true');
283283
});
284284

285+
test('when cookie does not exist', function () {
286+
expect(1);
287+
strictEqual($.removeCookie('c'), true, 'returns true');
288+
});
289+
285290
test('when deletion failed', function () {
286291
expect(1);
287292
$.cookie('c', 'v');
@@ -299,11 +304,6 @@ test('when deletion failed', function () {
299304
$.cookie = originalCookie;
300305
});
301306

302-
test('when cookie does not exist', function () {
303-
expect(1);
304-
strictEqual($.removeCookie('c'), false, 'returns false');
305-
});
306-
307307
test('with options', function () {
308308
expect(1);
309309
var options = { path: '/' };

0 commit comments

Comments
 (0)