Skip to content

Commit f6180cf

Browse files
Remove json option
1 parent 84d838b commit f6180cf

2 files changed

Lines changed: 2 additions & 72 deletions

File tree

‎src/js.cookie.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@
5151
value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
5252
}
5353

54-
value = decode(value, unallowedCharsInValue);
55-
56-
try {
57-
return api.json ? JSON.parse(value) : value;
58-
} catch(e) {}
54+
return decode(value, unallowedCharsInValue);
5955
}
6056

6157
function read(s, converter) {
@@ -93,7 +89,7 @@
9389
}
9490

9591
return (document.cookie = [
96-
encode(key, unallowedCharsInName), '=', encode(api.json ? JSON.stringify(value) : String(value), unallowedCharsInValue),
92+
encode(key, unallowedCharsInName), '=', encode(String(value), unallowedCharsInValue),
9793
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
9894
options.path ? '; path=' + options.path : '',
9995
options.domain ? '; domain=' + options.domain : '',

‎test/tests.js‎

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
var lifecycle = {
3737
teardown: function () {
3838
Cookies.defaults = {};
39-
delete Cookies.json;
4039
Object.keys(Cookies.get()).forEach(Cookies.remove);
4140
}
4241
};
@@ -76,53 +75,6 @@ test('equality sign in cookie value', function () {
7675
strictEqual(Cookies.get('c'), 'foo=bar', 'should include the entire value');
7776
});
7877

79-
test('json = true', function () {
80-
expect(1);
81-
82-
if ('JSON' in window) {
83-
Cookies.json = true;
84-
Cookies.set('c', { foo: 'bar' });
85-
deepEqual(Cookies.get('c'), { foo: 'bar' }, 'should parse JSON');
86-
} else {
87-
ok(true);
88-
}
89-
});
90-
91-
test('not existing with json = true', function () {
92-
expect(1);
93-
94-
if ('JSON' in window) {
95-
Cookies.json = true;
96-
strictEqual(Cookies.get('whatever'), undefined, "won't throw exception");
97-
} else {
98-
ok(true);
99-
}
100-
});
101-
102-
test('string with json = true', function () {
103-
expect(1);
104-
105-
if ('JSON' in window) {
106-
Cookies.json = true;
107-
Cookies.set('c', 'v');
108-
strictEqual(Cookies.get('c'), 'v', 'should return value');
109-
} else {
110-
ok(true);
111-
}
112-
});
113-
114-
test('invalid JSON string with json = true', function () {
115-
expect(1);
116-
117-
if ('JSON' in window) {
118-
Cookies.set('c', 'v');
119-
Cookies.json = true;
120-
strictEqual(Cookies.get('c'), undefined, "won't throw exception, returns undefined");
121-
} else {
122-
ok(true);
123-
}
124-
});
125-
12678
test('percent character in cookie value', function () {
12779
expect(1);
12880
document.cookie = 'bad=foo%';
@@ -166,12 +118,6 @@ test('Call to read all when there are no cookies at all', function () {
166118
deepEqual(Cookies.get(), {}, 'returns empty object');
167119
});
168120

169-
test('Call to read all with json: true', function () {
170-
Cookies.json = true;
171-
Cookies.set('c', { foo: 'bar' });
172-
deepEqual(Cookies.get(), { c: { foo: 'bar' } }, 'returns JSON parsed cookies');
173-
});
174-
175121
//github.com/carhartl/jquery-cookie/pull/62
176122
test('provide a way for decoding PHP whitespace encoding', function () {
177123
expect(1);
@@ -270,18 +216,6 @@ test('defaults', function () {
270216
ok(Cookies.set('c', 'v', { path: '/bar' }).match(/path=\/bar/), 'options argument has precedence');
271217
});
272218

273-
test('json = true', function () {
274-
expect(1);
275-
Cookies.json = true;
276-
277-
if ('JSON' in window) {
278-
Cookies.set('c', { foo: 'bar' });
279-
strictEqual(document.cookie, 'c=' + JSON.stringify({ foo: 'bar' }).replace(/"/g, '%22'), 'should stringify JSON');
280-
} else {
281-
ok(true);
282-
}
283-
});
284-
285219
test('Quote as the first character in the cookie value', function () {
286220
expect(1);
287221
Cookies.set('c', '"');

0 commit comments

Comments
 (0)