You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.3 KiB

  1. var assert = require('assert');
  2. var cookie = require('..');
  3. suite('parse');
  4. test('basic', function() {
  5. assert.deepEqual({ foo: 'bar' }, cookie.parse('foo=bar'));
  6. assert.deepEqual({ foo: '123' }, cookie.parse('foo=123'));
  7. });
  8. test('ignore spaces', function() {
  9. assert.deepEqual({ FOO: 'bar', baz: 'raz' },
  10. cookie.parse('FOO = bar; baz = raz'));
  11. });
  12. test('escaping', function() {
  13. assert.deepEqual({ foo: 'bar=123456789&name=Magic+Mouse' },
  14. cookie.parse('foo="bar=123456789&name=Magic+Mouse"'));
  15. assert.deepEqual({ email: ' ",;/' },
  16. cookie.parse('email=%20%22%2c%3b%2f'));
  17. });
  18. test('ignore escaping error and return original value', function() {
  19. assert.deepEqual({ foo: '%1', bar: 'bar' }, cookie.parse('foo=%1;bar=bar'));
  20. });
  21. test('ignore non values', function() {
  22. assert.deepEqual({ foo: '%1', bar: 'bar' }, cookie.parse('foo=%1;bar=bar;HttpOnly;Secure'));
  23. });
  24. test('unencoded', function() {
  25. assert.deepEqual({ foo: 'bar=123456789&name=Magic+Mouse' },
  26. cookie.parse('foo="bar=123456789&name=Magic+Mouse"',{
  27. decode: function(value) { return value; }
  28. }));
  29. assert.deepEqual({ email: '%20%22%2c%3b%2f' },
  30. cookie.parse('email=%20%22%2c%3b%2f',{
  31. decode: function(value) { return value; }
  32. }));
  33. })