Skip to content

Commit 655bd68

Browse files
Change strategy for characters that are not allowed in cookie
Yes, most browsers we test accept the value without having to encode it, but then some mobile browser or some update in a modern browser will break it. Better safe than sorry.
1 parent acfab49 commit 655bd68

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

‎test/tests.js‎

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,22 @@ test('RFC 6265 - disallowed characters in cookie-octet', function () {
252252

253253
Cookies.set('whitespace', ' ');
254254
strictEqual(Cookies.get('whitespace'), ' ', 'should handle the whitespace character');
255-
strictEqual(document.cookie, 'whitespace=%20', 'need to encode the whitespace character');
255+
strictEqual(document.cookie, 'whitespace=%20', 'whitespace is not allowed, need to encode');
256256
Cookies.remove('whitespace');
257257

258258
Cookies.set('comma', ',');
259259
strictEqual(Cookies.get('comma'), ',', 'should handle the comma character');
260-
strictEqual(document.cookie, 'comma=%2C', 'need to encode the comma character');
260+
strictEqual(document.cookie, 'comma=%2C', 'comma is not allowed, need to encode');
261261
Cookies.remove('comma');
262262

263263
Cookies.set('semicolon', ';');
264264
strictEqual(Cookies.get('semicolon'), ';', 'should handle the semicolon character');
265-
strictEqual(document.cookie, 'semicolon=%3B', 'need to encode the semicolon character');
265+
strictEqual(document.cookie, 'semicolon=%3B', 'semicolon is not allowed, need to encode');
266266
Cookies.remove('semicolon');
267267

268268
Cookies.set('backslash', '\\');
269269
strictEqual(Cookies.get('backslash'), '\\', 'should handle the backslash character');
270-
strictEqual(document.cookie, 'backslash=\\', 'there is no need to encode the backslash character');
270+
strictEqual(document.cookie, 'backslash=%5C', 'backslash is not allowed, need to encode');
271271
Cookies.remove('backslash');
272272

273273
Cookies.set('multiple', '" ,;\\" ,;\\');
@@ -280,92 +280,92 @@ test('RFC 6265 - disallowed characters in cookie-name', function () {
280280

281281
Cookies.set('(', 'v');
282282
strictEqual(Cookies.get('('), 'v', 'should handle the opening parens character');
283-
strictEqual(document.cookie, '(=v', 'there is no need to encode the opening parens character');
283+
strictEqual(document.cookie, '%28=v', 'opening parens is not allowed, need to encode');
284284
Cookies.remove('(');
285285

286286
Cookies.set(')', 'v');
287287
strictEqual(Cookies.get(')'), 'v', 'should handle the closing parens character');
288-
strictEqual(document.cookie, ')=v', 'there is no need to encode the closing parens character');
288+
strictEqual(document.cookie, '%29=v', 'closing parens is not allowed, need to encode');
289289
Cookies.remove(')');
290290

291291
Cookies.set('<', 'v');
292292
strictEqual(Cookies.get('<'), 'v', 'should handle the less-than character');
293-
strictEqual(document.cookie, '<=v', 'there is no need to encode the less-than character');
293+
strictEqual(document.cookie, '%3C=v', 'less-than is not allowed, need to encode');
294294
Cookies.remove('<');
295295

296296
Cookies.set('>', 'v');
297297
strictEqual(Cookies.get('>'), 'v', 'should handle the greater-than character');
298-
strictEqual(document.cookie, '>=v', 'there is no need to encode the greater-than character');
298+
strictEqual(document.cookie, '%3E=v', 'greater-than is not allowed, need to encode');
299299
Cookies.remove('>');
300300

301301
Cookies.set('@', 'v');
302302
strictEqual(Cookies.get('@'), 'v', 'should handle the at character');
303-
strictEqual(document.cookie, '@=v', 'there is no need to encode the at character');
303+
strictEqual(document.cookie, '%40=v', 'at is not allowed, need to encode');
304304
Cookies.remove('@');
305305

306306
Cookies.set(',', 'v');
307307
strictEqual(Cookies.get(','), 'v', 'should handle the comma character');
308-
strictEqual(document.cookie, '%2C=v', 'need to encode the comma character');
308+
strictEqual(document.cookie, '%2C=v', 'comma is not allowed');
309309
Cookies.remove(',');
310310

311311
Cookies.set(';', 'v');
312312
strictEqual(Cookies.get(';'), 'v', 'should handle the semicolon character');
313-
strictEqual(document.cookie, '%3B=v', 'need to encode the semicolon character');
313+
strictEqual(document.cookie, '%3B=v', 'semicolon is not allowed');
314314
Cookies.remove(';');
315315

316316
Cookies.set(':', 'v');
317317
strictEqual(Cookies.get(':'), 'v', 'should handle the colon character');
318-
strictEqual(document.cookie, ':=v', 'there is no need to encode the colon character');
318+
strictEqual(document.cookie, '%3A=v', 'colon is not allowed, need to encode');
319319
Cookies.remove(':');
320320

321321
Cookies.set('\\', 'v');
322322
strictEqual(Cookies.get('\\'), 'v', 'should handle the backslash character');
323-
strictEqual(document.cookie, '\\=v', 'there is no need to encode the backslash character');
323+
strictEqual(document.cookie, '%5C=v', 'backslash is not allowed, need to encode');
324324
Cookies.remove('\\');
325325

326326
Cookies.set('"', 'v');
327327
strictEqual(Cookies.get('"'), 'v', 'should handle the double quote character');
328-
strictEqual(document.cookie, '%22=v', 'need to encode the double quote character');
328+
strictEqual(document.cookie, '%22=v', 'double quote is not allowed');
329329
Cookies.remove('"');
330330

331331
Cookies.set('/', 'v');
332332
strictEqual(Cookies.get('/'), 'v', 'should handle the slash character');
333-
strictEqual(document.cookie, '/=v', 'there is no need to encode the slash character');
333+
strictEqual(document.cookie, '%2F=v', 'slash is not allowed, need to encode');
334334
Cookies.remove('/');
335335

336336
Cookies.set('[', 'v');
337337
strictEqual(Cookies.get('['), 'v', 'should handle the opening square brackets character');
338-
strictEqual(document.cookie, '[=v', 'there is no need to encode the opening square brackets character');
338+
strictEqual(document.cookie, '%5B=v', 'opening square brackets is not allowed, need to encode');
339339
Cookies.remove('[');
340340

341341
Cookies.set(']', 'v');
342342
strictEqual(Cookies.get(']'), 'v', 'should handle the closing square brackets character');
343-
strictEqual(document.cookie, ']=v', 'there is no need to encode the closing square brackets character');
343+
strictEqual(document.cookie, '%5D=v', 'closing square brackets is not allowed, need to encode');
344344
Cookies.remove(']');
345345

346346
Cookies.set('?', 'v');
347347
strictEqual(Cookies.get('?'), 'v', 'should handle the question mark character');
348-
strictEqual(document.cookie, '?=v', 'there is no need to encode the question mark character');
348+
strictEqual(document.cookie, '%3F=v', 'question mark is not allowed, need to encode');
349349
Cookies.remove('?');
350350

351351
Cookies.set('=', 'v');
352352
strictEqual(Cookies.get('='), 'v', 'should handle the equal sign character');
353-
strictEqual(document.cookie, '%3D=v', 'need to encode the equal sign character');
353+
strictEqual(document.cookie, '%3D=v', 'equal sign is not allowed');
354354
Cookies.remove('=');
355355

356356
Cookies.set('{', 'v');
357357
strictEqual(Cookies.get('{'), 'v', 'should handle the opening curly brackets character');
358-
strictEqual(document.cookie, '{=v', 'there is no need to encode the opening curly brackets character');
358+
strictEqual(document.cookie, '%7B=v', 'opening curly brackets is not allowed, need to encode');
359359
Cookies.remove('{');
360360

361361
Cookies.set('}', 'v');
362362
strictEqual(Cookies.get('}'), 'v', 'should handle the closing curly brackets character');
363-
strictEqual(document.cookie, '}=v', 'there is no need to encode the closing curly brackets character');
363+
strictEqual(document.cookie, '%7D=v', 'closing curly brackets is not allowed, need to encode');
364364
Cookies.remove('}');
365365

366366
Cookies.set(' ', 'v');
367367
strictEqual(Cookies.get(' '), 'v', 'should handle the horizontal tab character');
368-
strictEqual(document.cookie, '%09=v', 'need to encode the horizontal tab character');
368+
strictEqual(document.cookie, '%09=v', 'horizontal tab is not allowed');
369369
Cookies.remove(' ');
370370
});
371371

0 commit comments

Comments
 (0)