tough-cookie 1.1.0 → 1.2.0

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.
package/README.md CHANGED
@@ -28,8 +28,6 @@ It's _so_ easy!
28
28
 
29
29
  `npm install tough-cookie`
30
30
 
31
- Requires `punycode`, which should get installed automatically for you. Note that node.js v0.6.2+ bundles punycode by default.
32
-
33
31
  Why the name? NPM modules `cookie`, `cookies` and `cookiejar` were already taken.
34
32
 
35
33
  # API
@@ -375,15 +373,16 @@ The implementation MUST NOT pass an error if the cookie doesn't exist; only pass
375
373
  store.removeCookies(domain, path, cb(err))
376
374
  ------------------------------------------
377
375
 
378
- Removes matching cookies from the store. The `path` paramter is optional, and if missing means all paths in a domain should be removed.
376
+ Removes matching cookies from the store. The `path` parameter is optional, and if missing means all paths in a domain should be removed.
379
377
 
380
378
  Pass an error ONLY if removing any existing cookies failed.
381
379
 
382
- # TODO
380
+ MemoryCookieStore
381
+ =================
382
+
383
+ Inherits from Store.
383
384
 
384
- * _full_ RFC5890/RFC5891 canonicalization for domains in `cdomain()`
385
- * the optional `punycode` requirement implements RFC3492, but RFC6265 requires RFC5891
386
- * better tests for `validate()`?
385
+ Just-in-memory CookieJar synchronous store implementation, used by default.
387
386
 
388
387
  # Copyright and License
389
388
 
package/lib/cookie.js CHANGED
@@ -33,6 +33,8 @@ var net = require('net');
33
33
  var urlParse = require('url').parse;
34
34
  var pubsuffix = require('./pubsuffix');
35
35
  var Store = require('./store').Store;
36
+ var MemoryCookieStore = require('./memstore').MemoryCookieStore;
37
+ var pathMatch = require('./pathMatch').pathMatch;
36
38
 
37
39
  var punycode;
38
40
  try {
@@ -313,34 +315,6 @@ function defaultPath(path) {
313
315
  return path.slice(0, rightSlash);
314
316
  }
315
317
 
316
- /*
317
- * "A request-path path-matches a given cookie-path if at least one of the
318
- * following conditions holds:"
319
- */
320
- function pathMatch(reqPath,cookiePath) {
321
- // "o The cookie-path and the request-path are identical."
322
- if (cookiePath === reqPath) {
323
- return true;
324
- }
325
-
326
- var idx = reqPath.indexOf(cookiePath);
327
- if (idx === 0) {
328
- // "o The cookie-path is a prefix of the request-path, and the last
329
- // character of the cookie-path is %x2F ("/")."
330
- if (cookiePath.substr(-1) === "/") {
331
- return true;
332
- }
333
-
334
- // " o The cookie-path is a prefix of the request-path, and the first
335
- // character of the request-path that is not included in the cookie- path
336
- // is a %x2F ("/") character."
337
- if (reqPath.substr(cookiePath.length,1) === "/") {
338
- return true;
339
- }
340
- }
341
-
342
- return false;
343
- }
344
318
 
345
319
  function parse(str) {
346
320
  str = str.trim();
@@ -557,28 +531,6 @@ function cookieCompare(a,b) {
557
531
  return aTime - bTime;
558
532
  }
559
533
 
560
- // Gives the permutation of all possible domainMatch()es of a given domain. The
561
- // array is in shortest-to-longest order. Handy for indexing.
562
- function permuteDomain(domain) {
563
- var pubSuf = pubsuffix.getPublicSuffix(domain);
564
- if (!pubSuf) {
565
- return null;
566
- }
567
- if (pubSuf == domain) {
568
- return [domain];
569
- }
570
-
571
- var prefix = domain.slice(0,-(pubSuf.length+1)); // ".example.com"
572
- var parts = prefix.split('.').reverse();
573
- var cur = pubSuf;
574
- var permutations = [cur];
575
- while (parts.length) {
576
- cur = parts.shift()+'.'+cur;
577
- permutations.push(cur);
578
- }
579
- return permutations;
580
- }
581
-
582
534
  // Gives the permutation of all possible pathMatch()es of a given path. The
583
535
  // array is in longest-to-shortest order. Handy for indexing.
584
536
  function permutePath(path) {
@@ -602,9 +554,9 @@ function permutePath(path) {
602
554
  }
603
555
 
604
556
  function getCookieContext(url) {
605
- if(url instanceof Object)
557
+ if (url instanceof Object) {
606
558
  return url;
607
-
559
+ }
608
560
  // NOTE: decodeURI will throw on malformed URIs (see GH-32).
609
561
  // Therefore, we will just skip decoding for such URIs.
610
562
  try {
@@ -672,7 +624,7 @@ Cookie.prototype.validate = function validate() {
672
624
  if (!COOKIE_OCTETS.test(this.value)) {
673
625
  return false;
674
626
  }
675
- if (this.expires != Infinity && !(this.expires instanceof Date) && !parseDate(this.expires,true)) {
627
+ if (this.expires != Infinity && !(this.expires instanceof Date) && !parseDate(this.expires)) {
676
628
  return false;
677
629
  }
678
630
  if (this.maxAge != null && this.maxAge <= 0) {
@@ -831,15 +783,13 @@ Cookie.prototype.canonicalizedDomain = function canonicalizedDomain() {
831
783
  };
832
784
 
833
785
 
834
- var memstore;
835
786
  function CookieJar(store, rejectPublicSuffixes) {
836
787
  if (rejectPublicSuffixes != null) {
837
788
  this.rejectPublicSuffixes = rejectPublicSuffixes;
838
789
  }
839
790
 
840
791
  if (!store) {
841
- memstore = memstore || require('./memstore');
842
- store = new memstore.MemoryCookieStore();
792
+ store = new MemoryCookieStore();
843
793
  }
844
794
  this.store = store;
845
795
  }
@@ -1122,6 +1072,7 @@ module.exports = {
1122
1072
  CookieJar: CookieJar,
1123
1073
  Cookie: Cookie,
1124
1074
  Store: Store,
1075
+ MemoryCookieStore: MemoryCookieStore,
1125
1076
  parseDate: parseDate,
1126
1077
  formatDate: formatDate,
1127
1078
  parse: parse,
@@ -1131,7 +1082,7 @@ module.exports = {
1131
1082
  pathMatch: pathMatch,
1132
1083
  getPublicSuffix: pubsuffix.getPublicSuffix,
1133
1084
  cookieCompare: cookieCompare,
1134
- permuteDomain: permuteDomain,
1085
+ permuteDomain: require('./permuteDomain').permuteDomain,
1135
1086
  permutePath: permutePath,
1136
1087
  canonicalDomain: canonicalDomain
1137
1088
  };
package/lib/memstore.js CHANGED
@@ -29,10 +29,9 @@
29
29
  * POSSIBILITY OF SUCH DAMAGE.
30
30
  */
31
31
  'use strict';
32
- var tough = require('./cookie');
33
32
  var Store = require('./store').Store;
34
- var permuteDomain = tough.permuteDomain;
35
- var pathMatch = tough.pathMatch;
33
+ var permuteDomain = require('./permuteDomain').permuteDomain;
34
+ var pathMatch = require('./pathMatch').pathMatch;
36
35
  var util = require('util');
37
36
 
38
37
  function MemoryCookieStore() {
@@ -0,0 +1,61 @@
1
+ /*!
2
+ * Copyright (c) 2015, Salesforce.com, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice,
9
+ * this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ * this list of conditions and the following disclaimer in the documentation
13
+ * and/or other materials provided with the distribution.
14
+ *
15
+ * 3. Neither the name of Salesforce.com nor the names of its contributors may
16
+ * be used to endorse or promote products derived from this software without
17
+ * specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ * POSSIBILITY OF SUCH DAMAGE.
30
+ */
31
+ "use strict";
32
+ /*
33
+ * "A request-path path-matches a given cookie-path if at least one of the
34
+ * following conditions holds:"
35
+ */
36
+ function pathMatch (reqPath, cookiePath) {
37
+ // "o The cookie-path and the request-path are identical."
38
+ if (cookiePath === reqPath) {
39
+ return true;
40
+ }
41
+
42
+ var idx = reqPath.indexOf(cookiePath);
43
+ if (idx === 0) {
44
+ // "o The cookie-path is a prefix of the request-path, and the last
45
+ // character of the cookie-path is %x2F ("/")."
46
+ if (cookiePath.substr(-1) === "/") {
47
+ return true;
48
+ }
49
+
50
+ // " o The cookie-path is a prefix of the request-path, and the first
51
+ // character of the request-path that is not included in the cookie- path
52
+ // is a %x2F ("/") character."
53
+ if (reqPath.substr(cookiePath.length, 1) === "/") {
54
+ return true;
55
+ }
56
+ }
57
+
58
+ return false;
59
+ }
60
+
61
+ exports.pathMatch = pathMatch;
@@ -0,0 +1,56 @@
1
+ /*!
2
+ * Copyright (c) 2015, Salesforce.com, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * Redistribution and use in source and binary forms, with or without
6
+ * modification, are permitted provided that the following conditions are met:
7
+ *
8
+ * 1. Redistributions of source code must retain the above copyright notice,
9
+ * this list of conditions and the following disclaimer.
10
+ *
11
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ * this list of conditions and the following disclaimer in the documentation
13
+ * and/or other materials provided with the distribution.
14
+ *
15
+ * 3. Neither the name of Salesforce.com nor the names of its contributors may
16
+ * be used to endorse or promote products derived from this software without
17
+ * specific prior written permission.
18
+ *
19
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ * POSSIBILITY OF SUCH DAMAGE.
30
+ */
31
+ "use strict";
32
+ var pubsuffix = require('./pubsuffix');
33
+
34
+ // Gives the permutation of all possible domainMatch()es of a given domain. The
35
+ // array is in shortest-to-longest order. Handy for indexing.
36
+ function permuteDomain (domain) {
37
+ var pubSuf = pubsuffix.getPublicSuffix(domain);
38
+ if (!pubSuf) {
39
+ return null;
40
+ }
41
+ if (pubSuf == domain) {
42
+ return [domain];
43
+ }
44
+
45
+ var prefix = domain.slice(0, -(pubSuf.length + 1)); // ".example.com"
46
+ var parts = prefix.split('.').reverse();
47
+ var cur = pubSuf;
48
+ var permutations = [cur];
49
+ while (parts.length) {
50
+ cur = parts.shift() + '.' + cur;
51
+ permutations.push(cur);
52
+ }
53
+ return permutations;
54
+ }
55
+
56
+ exports.permuteDomain = permuteDomain;
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "RFC6265",
14
14
  "RFC2965"
15
15
  ],
16
- "version": "1.1.0",
16
+ "version": "1.2.0",
17
17
  "homepage": "https://github.com/SalesforceEng/tough-cookie",
18
18
  "repository": {
19
19
  "type": "git",
package/CONTRIBUTING.md DELETED
@@ -1,9 +0,0 @@
1
- # Contributing
2
-
3
- This is the contribution guide for tough-cookie.
4
-
5
- ## CLA
6
-
7
- As with all Salesforce open-source projects, tough-cookie requires a Contributor License Agreement to be signed by you (or your company).
8
-
9
-
@@ -1,6 +0,0 @@
1
- async (0.1.18) MIT (http://github.com/caolan/async/raw/master/LICENSE) node_modules/async/package.json
2
- diff (1.0.8) BSD (http://github.com/kpdecker/jsdiff/blob/master/LICENSE) node_modules/vows/node_modules/diff/package.json
3
- eyes (0.1.8) MIT License (https://spdx.org/licenses/MIT) node_modules/vows/node_modules/eyes/package.json
4
- punycode (1.0.0) MIT (http://mths.be/mit) node_modules/punycode/package.json
5
- tough-cookie (0.12.1) MIT License (https://spdx.org/licenses/MIT) package.json
6
- vows (0.7.0) MIT License (https://spdx.org/licenses/MIT) node_modules/vows/LICENSE