Skip to content

Commit 0c8f5e1

Browse files
Do not create cookie if using .set() incorrectly
Closes js-cookiegh-168. Closes js-cookiegh-145.
1 parent dc8f437 commit 0c8f5e1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/js.cookie.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@
125125
return result;
126126
}
127127

128-
api.get = api.set = api;
128+
api.set = api;
129+
api.get = function (key) {
130+
return api(key);
131+
};
129132
api.getJSON = function () {
130133
return api.apply({
131134
json: true

test/tests.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ QUnit.test('Call to read cookie when there is another unrelated cookie with malf
8989
Cookies.withConverter(unescape).remove('invalid');
9090
});
9191

92+
// github.com/js-cookie/js-cookie/issues/145
93+
QUnit.test('Call to read cookie when passing an Object Literal as the second argument', function (assert) {
94+
assert.expect(1);
95+
Cookies.get('name', { path: '' });
96+
assert.strictEqual(document.cookie, '', 'should not create a cookie');
97+
});
98+
9299
QUnit.module('write', lifecycle);
93100

94101
QUnit.test('String primitive', function (assert) {

0 commit comments

Comments
 (0)