Skip to content

Commit ef3c946

Browse files
committed
Prevent accidentally writing cookie in getJSON()
1 parent 8b2a880 commit ef3c946

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/js.cookie.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@
140140
api.get = function (key) {
141141
return api.call(api, key);
142142
};
143-
api.getJSON = function () {
144-
return api.apply({
143+
api.getJSON = function (key) {
144+
return api.call({
145145
json: true
146-
}, arguments);
146+
}, key);
147147
};
148148
api.remove = function (key, attributes) {
149149
api(key, '', extend(attributes, {

test/tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ QUnit.test('Cookies with escaped quotes in json using raw converters', function
474474
assert.strictEqual(Cookies.get('c'), '{ \\"foo\\": \\"bar\\" }', 'returns unparsed cookie with enclosing quotes removed');
475475
});
476476

477+
QUnit.test('Prevent accidentally writing cookie when passing unexpected argument', function (assert) {
478+
Cookies.getJSON('c', { foo: 'bar' });
479+
assert.strictEqual(Cookies.get('c'), undefined, 'should not write any cookie');
480+
});
481+
477482
QUnit.module('noConflict', lifecycle);
478483

479484
QUnit.test('do not conflict with existent globals', function (assert) {

0 commit comments

Comments
 (0)