Skip to content

Commit c00df64

Browse files
Make sure cookies created outside js-cookie default instance are removed
PhantomJS is the only browser I tested that complains about it.
1 parent 573a638 commit c00df64

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

test/tests.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ test('should decode a malformed char that matches the decodeURIComponent regex',
220220
document.cookie = 'c=%E3';
221221
var cookies = Cookies.withConverter(unescape);
222222
strictEqual(cookies.get('c'), 'ã', 'should convert the character correctly');
223-
cookies.remove('c');
223+
cookies.remove('c', {
224+
path: ''
225+
});
224226
});
225227

226228
test('should be able to conditionally decode a single malformed cookie', function () {
@@ -230,6 +232,7 @@ test('should be able to conditionally decode a single malformed cookie', functio
230232
return unescape(value);
231233
}
232234
});
235+
233236
document.cookie = 'escaped=%u5317';
234237
strictEqual(cookies.get('escaped'), '北', 'should use a custom method for escaped cookie');
235238

@@ -241,7 +244,11 @@ test('should be able to conditionally decode a single malformed cookie', functio
241244
encoded: '京'
242245
}, 'should retrieve everything');
243246

244-
Object.keys(cookies.get()).forEach(cookies.remove);
247+
Object.keys(cookies.get()).forEach(function (name) {
248+
cookies.remove(name, {
249+
path: ''
250+
});
251+
});
245252
strictEqual(document.cookie, '', 'should remove everything');
246253
});
247254

@@ -320,4 +327,3 @@ test('do not conflict with existent globals', function () {
320327
strictEqual(window.Cookies, 'existent global', 'should restore the original global');
321328
window.Cookies = Cookies;
322329
});
323-

test/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@
3434

3535
window.lifecycle = {
3636
teardown: function () {
37+
// Remove the cookies created using js-cookie default attributes
3738
Object.keys(Cookies.get()).forEach(Cookies.remove);
39+
// Remove the cookies created using browser default attributes
40+
Object.keys(Cookies.get()).forEach(function (cookie) {
41+
Cookies.remove(cookie, {
42+
path: ''
43+
});
44+
});
3845
}
3946
};
4047
}());

0 commit comments

Comments
 (0)