Skip to content

Commit 38dc9e2

Browse files
Deleting an attribute should roll back to the default definition
1 parent bc4b822 commit 38dc9e2

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/js.cookie.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
// Write
3939

4040
if (arguments.length > 1) {
41-
options = extend(api.defaults, options);
41+
options = extend({
42+
path: '/'
43+
}, api.defaults, options);
4244

4345
if (typeof options.expires === 'number') {
4446
var expires = new Date();
@@ -118,9 +120,7 @@
118120
json: true
119121
}, [].slice.call(arguments));
120122
};
121-
api.defaults = {
122-
path: '/'
123-
};
123+
api.defaults = {};
124124

125125
api.remove = function (key, options) {
126126
api(key, '', extend(options, {

test/tests.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ test('return value', function () {
164164

165165
test('default path attribute', function () {
166166
expect(1);
167-
ok(Cookies.set('c', 'v').match(/path=\//), 'should be default to the whole site');
167+
ok(Cookies.set('c', 'v').match(/path=\//), 'should read the default path');
168168
});
169169

170-
test('changing defaults', function () {
171-
expect(2);
170+
test('API for changing defaults', function () {
171+
expect(3);
172172

173173
Cookies.defaults.path = '/foo';
174174
ok(Cookies.set('c', 'v').match(/path=\/foo/), 'should use attributes from defaults');
@@ -178,6 +178,7 @@ test('changing defaults', function () {
178178
Cookies.remove( 'c', { path: '/bar' });
179179

180180
delete Cookies.defaults.path;
181+
ok(Cookies.set('c', 'v').match(/path=\//), 'should roll back to the default path');
181182
});
182183

183184
module('remove', lifecycle);

0 commit comments

Comments
 (0)