tough-cookie 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +17 -3
  2. package/lib/cookie.js +9 -15
  3. package/package.json +3 -2
package/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  [RFC6265](https://tools.ietf.org/html/rfc6265) Cookies and CookieJar for Node.js
2
2
 
3
- [![Build Status](https://travis-ci.org/SalesforceEng/tough-cookie.png?branch=master)](https://travis-ci.org/SalesforceEng/tough-cookie)
3
+ [![npm package](https://nodei.co/npm/tough-cookie.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/tough-cookie/)
4
4
 
5
- [![NPM Stats](https://nodei.co/npm/tough-cookie.png?downloads=true&stars=true)](https://npmjs.org/package/tough-cookie)
6
- ![NPM Downloads](https://nodei.co/npm-dl/tough-cookie.png?months=9)
5
+ [![Build Status](https://travis-ci.org/SalesforceEng/tough-cookie.png?branch=master)](https://travis-ci.org/SalesforceEng/tough-cookie)
7
6
 
8
7
  # Synopsis
9
8
 
@@ -30,6 +29,10 @@ It's _so_ easy!
30
29
 
31
30
  Why the name? NPM modules `cookie`, `cookies` and `cookiejar` were already taken.
32
31
 
32
+ ## Version Support
33
+
34
+ Support for versions of node.js will follow that of the [request](https://www.npmjs.com/package/request) module.
35
+
33
36
  # API
34
37
 
35
38
  ## tough
@@ -426,6 +429,17 @@ Inherits from `Store`.
426
429
 
427
430
  A just-in-memory CookieJar synchronous store implementation, used by default. Despite being a synchronous implementation, it's usable with both the synchronous and asynchronous forms of the `CookieJar` API.
428
431
 
432
+ ## Community Cookie Stores
433
+
434
+ These are some Store implementations authored and maintained by the community. They aren't official and we don't vouch for them but you may be interested to have a look:
435
+
436
+ - [`db-cookie-store`](https://github.com/JSBizon/db-cookie-store): SQL including SQLite-based databases
437
+ - [`file-cookie-store`](https://github.com/JSBizon/file-cookie-store): Netscape cookie file format on disk
438
+ - [`redis-cookie-store`](https://github.com/benkroeger/redis-cookie-store): Redis
439
+ - [`tough-cookie-filestore`](https://github.com/mitsuru/tough-cookie-filestore): JSON on disk
440
+ - [`tough-cookie-web-storage-store`](https://github.com/exponentjs/tough-cookie-web-storage-store): DOM localStorage and sessionStorage
441
+
442
+
429
443
  # Serialization Format
430
444
 
431
445
  **NOTE**: if you want to have custom `Cookie` properties serialized, add the property name to `Cookie.serializableProperties`.
package/lib/cookie.js CHANGED
@@ -58,19 +58,16 @@ var CONTROL_CHARS = /[\x00-\x1F]/;
58
58
  // (see: https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/parsed_cookie.cc#L60)
59
59
  // '=' and ';' are attribute/values separators
60
60
  // (see: https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/parsed_cookie.cc#L64)
61
- var COOKIE_PAIR = /^(([^=;]+))\s*=\s*(("?)[^\n\r\0]*\3)/
61
+ var COOKIE_PAIR = /^(([^=;]+))\s*=\s*([^\n\r\0]*)/;
62
62
 
63
63
  // Used to parse non-RFC-compliant cookies like '=abc' when given the `loose`
64
64
  // option in Cookie.parse:
65
- var LOOSE_COOKIE_PAIR = /^((?:=)?([^=;]*)\s*=\s*)?(("?)[^\n\r\0]*\3)/;
65
+ var LOOSE_COOKIE_PAIR = /^((?:=)?([^=;]*)\s*=\s*)?([^\n\r\0]*)/;
66
66
 
67
67
  // RFC6265 S4.1.1 defines path value as 'any CHAR except CTLs or ";"'
68
68
  // Note ';' is \x3B
69
69
  var PATH_VALUE = /[\x20-\x3A\x3C-\x7E]+/;
70
70
 
71
- // Used for checking whether or not there is a trailing semi-colon
72
- var TRAILING_SEMICOLON = /;+$/;
73
-
74
71
  var DAY_OF_MONTH = /^(\d{1,2})[^\d]*$/;
75
72
  var TIME = /^(\d{1,2})[^\d]*:(\d{1,2})[^\d]*:(\d{1,2})[^\d]*$/;
76
73
  var MONTH = /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i;
@@ -327,12 +324,6 @@ function parse(str, options) {
327
324
  }
328
325
  str = str.trim();
329
326
 
330
- // S4.1.1 Trailing semi-colons are not part of the specification.
331
- var semiColonCheck = TRAILING_SEMICOLON.exec(str);
332
- if (semiColonCheck) {
333
- str = str.slice(0, semiColonCheck.index);
334
- }
335
-
336
327
  // We use a regex to parse the "name-value-pair" part of S5.2
337
328
  var firstSemi = str.indexOf(';'); // S5.2 step 1
338
329
  var pairRe = options.loose ? LOOSE_COOKIE_PAIR : COOKIE_PAIR;
@@ -362,7 +353,7 @@ function parse(str, options) {
362
353
  // S5.2.3 "unparsed-attributes consist of the remainder of the set-cookie-string
363
354
  // (including the %x3B (";") in question)." plus later on in the same section
364
355
  // "discard the first ";" and trim".
365
- var unparsed = str.slice(firstSemi).replace(/^\s*;\s*/,'').trim();
356
+ var unparsed = str.slice(firstSemi + 1).trim();
366
357
 
367
358
  // "If the unparsed-attributes string is empty, skip the rest of these
368
359
  // steps."
@@ -378,9 +369,12 @@ function parse(str, options) {
378
369
  * cookie-attribute-list". Therefore, in this implementation, we overwrite
379
370
  * the previous value.
380
371
  */
381
- var cookie_avs = unparsed.split(/\s*;\s*/);
372
+ var cookie_avs = unparsed.split(';');
382
373
  while (cookie_avs.length) {
383
- var av = cookie_avs.shift();
374
+ var av = cookie_avs.shift().trim();
375
+ if (av.length === 0) { // happens if ";;" appears
376
+ continue;
377
+ }
384
378
  var av_sep = av.indexOf('=');
385
379
  var av_key, av_value;
386
380
 
@@ -1265,7 +1259,6 @@ CookieJar.deserialize = function(strOrObj, store, cb) {
1265
1259
  });
1266
1260
  };
1267
1261
 
1268
- CookieJar.fromJSON = CookieJar.deserializeSync;
1269
1262
  CookieJar.deserializeSync = function(strOrObj, store) {
1270
1263
  var serialized = typeof strOrObj === 'string' ?
1271
1264
  JSON.parse(strOrObj) : strOrObj;
@@ -1279,6 +1272,7 @@ CookieJar.deserializeSync = function(strOrObj, store) {
1279
1272
  jar._importCookiesSync(serialized);
1280
1273
  return jar;
1281
1274
  };
1275
+ CookieJar.fromJSON = CookieJar.deserializeSync;
1282
1276
 
1283
1277
  CAN_BE_SYNC.push('clone');
1284
1278
  CookieJar.prototype.clone = function(newStore, cb) {
package/package.json CHANGED
@@ -43,7 +43,7 @@
43
43
  "RFC6265",
44
44
  "RFC2965"
45
45
  ],
46
- "version": "2.2.0",
46
+ "version": "2.3.1",
47
47
  "homepage": "https://github.com/SalesforceEng/tough-cookie",
48
48
  "repository": {
49
49
  "type": "git",
@@ -61,10 +61,11 @@
61
61
  "test": "vows test/*_test.js"
62
62
  },
63
63
  "engines": {
64
- "node": ">=0.10.0"
64
+ "node": ">=0.8"
65
65
  },
66
66
  "devDependencies": {
67
67
  "async": "^1.4.2",
68
+ "string.prototype.repeat": "^0.2.0",
68
69
  "vows": "^0.8.1"
69
70
  }
70
71
  }