Skip to content

Commit 6f6210f

Browse files
Try to figure out how to handle cookie-octet enclosed in quotes
1 parent 78a3b44 commit 6f6210f

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎src/js.cookie.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848

4949
function processRead (value, converter, json) {
5050
if (value.charAt(0) === '"') {
51-
// This is a quoted cookie as according to RFC2068, unescape...
52-
value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
51+
value = value.slice(1, -1);
5352
}
5453

5554
value = decode(value, unallowedCharsInValue);

‎test/tests.js‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ test('not existing', function () {
6262
strictEqual(Cookies.get('whatever'), undefined, 'return undefined');
6363
});
6464

65-
test('RFC 2068 quoted string', function () {
66-
expect(1);
67-
document.cookie = 'c="v@address.com\\"\\\\\\""';
68-
strictEqual(Cookies.get('c'), 'v@address.com"\\"', 'should decode RFC 2068 quoted string');
69-
});
70-
7165
// github.com/carhartl/jquery-cookie/issues/50
7266
test('equality sign in cookie value', function () {
7367
expect(1);
@@ -216,7 +210,7 @@ test('defaults', function () {
216210
ok(Cookies.set('c', 'v', { path: '/bar' }).match(/path=\/bar/), 'options argument has precedence');
217211
});
218212

219-
test('Quote in the cookie value', function () {
213+
test('Handling quotes in the cookie value for read and write', function () {
220214
expect(3);
221215

222216
Cookies.set('quote', '"');
@@ -229,7 +223,19 @@ test('Quote in the cookie value', function () {
229223
strictEqual(Cookies.get('without-first'), 'content"', 'should print the quote character');
230224
});
231225

232-
test('RFC 6265 disallowed characters in cookie-octet', function () {
226+
test('RFC 6265 - cookie-octet enclosed in DQUOTE', function () {
227+
expect(1);
228+
document.cookie = 'c="v"';
229+
strictEqual(Cookies.get('c'), 'v', 'should decode the quotes');
230+
});
231+
232+
test('RFC 6265 - cookie-octet with quotes enclosed in DQUOTE', function() {
233+
expect(1);
234+
document.cookie = 'c="with"quotes"';
235+
strictEqual(Cookies.get('c'), 'with"quotes', 'should decode the quotes');
236+
});
237+
238+
test('RFC 6265 - disallowed characters in cookie-octet', function () {
233239
expect(5);
234240

235241
Cookies.set('whitespace', ' ');
@@ -248,7 +254,7 @@ test('RFC 6265 disallowed characters in cookie-octet', function () {
248254
strictEqual(Cookies.get('multiple'), '" ,;\\" ,;\\', 'should handle multiple special characters');
249255
});
250256

251-
test('RFC 6265 disallowed characters in cookie-name', function () {
257+
test('RFC 6265 - disallowed characters in cookie-name', function () {
252258
expect(18);
253259

254260
Cookies.set('(', 'v');

0 commit comments

Comments
 (0)