diff --git a/src/js.cookie.mjs b/src/js.cookie.mjs index cd93d315..071aaf21 100644 --- a/src/js.cookie.mjs +++ b/src/js.cookie.mjs @@ -15,20 +15,15 @@ function decode (s) { } function init (converter) { - var defaults = {} + var defaults = { + path: '/' + } function set (key, value, attributes) { if (typeof document === 'undefined') { return } - - attributes = extend( - { - path: '/' - }, - defaults, - attributes - ) + attributes = extend(defaults, attributes) if (typeof attributes.expires === 'number') { attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e5) diff --git a/test/tests.js b/test/tests.js index b8b5fadd..e623809f 100644 --- a/test/tests.js +++ b/test/tests.js @@ -318,7 +318,7 @@ QUnit.test('API for changing defaults', function (assert) { Cookies.set('c', 'v').match(/path=\/foo/), 'should use attributes from defaults' ) - Cookies.remove('c', { path: '/foo' }) + Cookies.remove('c') assert.ok( Cookies.set('c', 'v', { path: '/bar' }).match(/path=\/bar/), @@ -327,10 +327,9 @@ QUnit.test('API for changing defaults', function (assert) { Cookies.remove('c', { path: '/bar' }) delete Cookies.defaults.path - assert.ok( - Cookies.set('c', 'v').match(/path=\//), - 'should roll back to the default path' - ) + assert.notOk(Cookies.set('c', 'v').match(/path=/), 'should not set any path') + Cookies.remove('c') + Cookies.defaults.path = '/' }) QUnit.test('true secure value', function (assert) {