tough-cookie 0.12.1 → 0.13.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/.editorconfig +12 -0
- package/.npmignore +1 -0
- package/.travis.yml +2 -1
- package/LICENSE +22 -26
- package/README.md +32 -20
- package/generate-pubsuffix.js +54 -34
- package/lib/cookie.js +112 -69
- package/lib/memstore.js +44 -24
- package/lib/pubsuffix.js +27 -17
- package/lib/store.js +30 -0
- package/package.json +4 -4
- package/test/api_test.js +388 -0
- package/test/cookie_jar_test.js +468 -0
- package/test/cookie_sorting_test.js +90 -0
- package/test/cookie_to_json_test.js +164 -0
- package/test/cookie_to_string_test.js +162 -0
- package/test/date_test.js +79 -0
- package/test/domain_and_path_test.js +201 -0
- package/test/ietf_data/dates/bsd-examples.json +168 -0
- package/test/ietf_data/dates/examples.json +48 -0
- package/test/ietf_data/parser.json +1959 -0
- package/test/ietf_test.js +106 -0
- package/test/lifetime_test.js +97 -0
- package/test/parsing_test.js +356 -0
- package/test/regression_test.js +128 -0
- package/tough-cookie-deps.tsv +6 -0
- package/test.js +0 -1625
package/.editorconfig
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# This file is for unifying the coding style for different editors and IDEs
|
|
2
|
+
# editorconfig.org
|
|
3
|
+
|
|
4
|
+
root = true
|
|
5
|
+
|
|
6
|
+
[*]
|
|
7
|
+
end_of_line = lf
|
|
8
|
+
charset = utf-8
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
trim_trailing_whitespace = true
|
|
11
|
+
indent_style = space
|
|
12
|
+
indent_size = 2
|
package/.npmignore
CHANGED
package/.travis.yml
CHANGED
package/LICENSE
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
Copyright
|
|
2
|
-
|
|
3
|
-
of this software and associated documentation files (the "Software"), to
|
|
4
|
-
deal in the Software without restriction, including without limitation the
|
|
5
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
6
|
-
sell copies of the Software, and to permit persons to whom the Software is
|
|
7
|
-
furnished to do so, subject to the following conditions:
|
|
1
|
+
Copyright (c) 2015, Salesforce.com, Inc.
|
|
2
|
+
All rights reserved.
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
all copies or substantial portions of the Software.
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
11
5
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
IN THE SOFTWARE.
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
+
|
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
+
|
|
10
|
+
3. Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
11
|
+
|
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
13
|
+
|
|
14
|
+
===
|
|
19
15
|
|
|
20
16
|
The following exceptions apply:
|
|
21
17
|
|
|
@@ -37,24 +33,24 @@ under the terms of the MPL 1.1:
|
|
|
37
33
|
|
|
38
34
|
// ***** BEGIN LICENSE BLOCK *****
|
|
39
35
|
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
40
|
-
//
|
|
41
|
-
// The contents of this file are subject to the Mozilla Public License Version
|
|
42
|
-
// 1.1 (the "License"); you may not use this file except in compliance with
|
|
43
|
-
// the License. You may obtain a copy of the License at
|
|
36
|
+
//
|
|
37
|
+
// The contents of this file are subject to the Mozilla Public License Version
|
|
38
|
+
// 1.1 (the "License"); you may not use this file except in compliance with
|
|
39
|
+
// the License. You may obtain a copy of the License at
|
|
44
40
|
// http://www.mozilla.org/MPL/
|
|
45
|
-
//
|
|
41
|
+
//
|
|
46
42
|
// Software distributed under the License is distributed on an "AS IS" basis,
|
|
47
43
|
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
48
44
|
// for the specific language governing rights and limitations under the
|
|
49
45
|
// License.
|
|
50
|
-
//
|
|
46
|
+
//
|
|
51
47
|
// The Original Code is the Public Suffix List.
|
|
52
|
-
//
|
|
48
|
+
//
|
|
53
49
|
// The Initial Developer of the Original Code is
|
|
54
50
|
// Jo Hermans <jo.hermans@gmail.com>.
|
|
55
51
|
// Portions created by the Initial Developer are Copyright (C) 2007
|
|
56
52
|
// the Initial Developer. All Rights Reserved.
|
|
57
|
-
//
|
|
53
|
+
//
|
|
58
54
|
// Contributor(s):
|
|
59
55
|
// Ruben Arakelyan <ruben@rubenarakelyan.com>
|
|
60
56
|
// Gervase Markham <gerv@gerv.net>
|
|
@@ -62,7 +58,7 @@ under the terms of the MPL 1.1:
|
|
|
62
58
|
// David Triendl <david@triendl.name>
|
|
63
59
|
// Jothan Frakes <jothan@gmail.com>
|
|
64
60
|
// The kind representatives of many TLD registries
|
|
65
|
-
//
|
|
61
|
+
//
|
|
66
62
|
// Alternatively, the contents of this file may be used under the terms of
|
|
67
63
|
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
68
64
|
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
@@ -74,5 +70,5 @@ under the terms of the MPL 1.1:
|
|
|
74
70
|
// and other provisions required by the GPL or the LGPL. If you do not delete
|
|
75
71
|
// the provisions above, a recipient may use your version of this file under
|
|
76
72
|
// the terms of any one of the MPL, the GPL or the LGPL.
|
|
77
|
-
//
|
|
73
|
+
//
|
|
78
74
|
// ***** END LICENSE BLOCK *****
|
package/README.md
CHANGED
|
@@ -388,25 +388,37 @@ Pass an error ONLY if removing any existing cookies failed.
|
|
|
388
388
|
|
|
389
389
|
# Copyright and License
|
|
390
390
|
|
|
391
|
-
(tl;dr:
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
391
|
+
(tl;dr: BSD-3-Clause with some MPL/1.1)
|
|
392
|
+
|
|
393
|
+
```text
|
|
394
|
+
Copyright (c) 2015, Salesforce.com, Inc.
|
|
395
|
+
All rights reserved.
|
|
396
|
+
|
|
397
|
+
Redistribution and use in source and binary forms, with or without
|
|
398
|
+
modification, are permitted provided that the following conditions are met:
|
|
399
|
+
|
|
400
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
401
|
+
this list of conditions and the following disclaimer.
|
|
402
|
+
|
|
403
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
404
|
+
this list of conditions and the following disclaimer in the documentation
|
|
405
|
+
and/or other materials provided with the distribution.
|
|
406
|
+
|
|
407
|
+
3. Neither the name of Salesforce.com nor the names of its contributors may
|
|
408
|
+
be used to endorse or promote products derived from this software without
|
|
409
|
+
specific prior written permission.
|
|
410
|
+
|
|
411
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
412
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
413
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
414
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
415
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
416
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
417
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
418
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
419
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
420
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
421
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
422
|
+
```
|
|
411
423
|
|
|
412
424
|
Portions may be licensed under different licenses (in particular public-suffix.txt is MPL/1.1); please read the LICENSE file for full details.
|
package/generate-pubsuffix.js
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright
|
|
3
|
-
*
|
|
4
|
-
* of this software and associated documentation files (the "Software"), to
|
|
5
|
-
* deal in the Software without restriction, including without limitation the
|
|
6
|
-
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
7
|
-
* sell copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
* furnished to do so, subject to the following conditions:
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2015, Salesforce.com, Inc.
|
|
3
|
+
* All rights reserved.
|
|
9
4
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions are met:
|
|
12
7
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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.
|
|
20
30
|
*/
|
|
21
31
|
'use strict';
|
|
22
32
|
var fs = require('fs');
|
|
@@ -90,25 +100,35 @@ function addToIndex(index,line) {
|
|
|
90
100
|
|
|
91
101
|
// include the licence in the function since it gets written to pubsuffix.js
|
|
92
102
|
function getPublicSuffix(domain) {
|
|
93
|
-
|
|
94
|
-
* Copyright
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
103
|
+
/*!
|
|
104
|
+
* Copyright (c) 2015, Salesforce.com, Inc.
|
|
105
|
+
* All rights reserved.
|
|
106
|
+
*
|
|
107
|
+
* Redistribution and use in source and binary forms, with or without
|
|
108
|
+
* modification, are permitted provided that the following conditions are met:
|
|
109
|
+
*
|
|
110
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
111
|
+
* this list of conditions and the following disclaimer.
|
|
112
|
+
*
|
|
113
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
114
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
115
|
+
* and/or other materials provided with the distribution.
|
|
101
116
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
117
|
+
* 3. Neither the name of Salesforce.com nor the names of its contributors may
|
|
118
|
+
* be used to endorse or promote products derived from this software without
|
|
119
|
+
* specific prior written permission.
|
|
104
120
|
*
|
|
105
|
-
*
|
|
106
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
121
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
122
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
123
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
124
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
125
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
126
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
127
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
128
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
129
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
130
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
131
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
112
132
|
*/
|
|
113
133
|
if (!domain) {
|
|
114
134
|
return null;
|
package/lib/cookie.js
CHANGED
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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.
|
|
9
14
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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.
|
|
12
18
|
*
|
|
13
|
-
*
|
|
14
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
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.
|
|
20
30
|
*/
|
|
21
|
-
|
|
22
31
|
'use strict';
|
|
23
32
|
var net = require('net');
|
|
24
33
|
var urlParse = require('url').parse;
|
|
@@ -44,7 +53,13 @@ var COOKIE_OCTETS = new RegExp('^'+COOKIE_OCTET.source+'$');
|
|
|
44
53
|
|
|
45
54
|
// The name/key cannot be empty but the value can (S5.2):
|
|
46
55
|
var COOKIE_PAIR_STRICT = new RegExp('^('+TOKEN.source+'+)=("?)('+COOKIE_OCTET.source+'*)\\2$');
|
|
47
|
-
|
|
56
|
+
|
|
57
|
+
// Double quotes are part of the value (see: S4.1.1).
|
|
58
|
+
// '\r', '\n' and '\0' should be treated as a terminator in the "relaxed" mode
|
|
59
|
+
// (see: https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/parsed_cookie.cc#L60)
|
|
60
|
+
// '=' and ';' are attribute/values separators
|
|
61
|
+
// (see: https://github.com/ChromiumWebApps/chromium/blob/b3d3b4da8bb94c1b2e061600df106d590fda3620/net/cookies/parsed_cookie.cc#L64)
|
|
62
|
+
var COOKIE_PAIR = /^([^=;]+)\s*=\s*(("?)[^\n\r\0]*\3)/;
|
|
48
63
|
|
|
49
64
|
// RFC6265 S4.1.1 defines extension-av as 'any CHAR except CTLs or ";"'
|
|
50
65
|
// Note ';' is \x3B
|
|
@@ -55,21 +70,10 @@ var PATH_VALUE = NON_CTL_SEMICOLON;
|
|
|
55
70
|
// Used for checking whether or not there is a trailing semi-colon
|
|
56
71
|
var TRAILING_SEMICOLON = /;+$/;
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var DAY_OF_MONTH = /^(0?[1-9]|[12][0-9]|3[01])$/;
|
|
73
|
+
var DAY_OF_MONTH = /^(\d{1,2})[^\d]*$/;
|
|
74
|
+
var TIME = /^(\d{1,2})[^\d]*:(\d{1,2})[^\d]*:(\d{1,2})[^\d]*$/;
|
|
75
|
+
var MONTH = /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)/i;
|
|
62
76
|
|
|
63
|
-
/* RFC6265 S5.1.1.5:
|
|
64
|
-
* [fail if]
|
|
65
|
-
* * the hour-value is greater than 23,
|
|
66
|
-
* * the minute-value is greater than 59, or
|
|
67
|
-
* * the second-value is greater than 59.
|
|
68
|
-
*/
|
|
69
|
-
var TIME = /(0?[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])/;
|
|
70
|
-
var STRICT_TIME = /^(0?[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/;
|
|
71
|
-
|
|
72
|
-
var MONTH = /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$/i;
|
|
73
77
|
var MONTH_TO_NUM = {
|
|
74
78
|
jan:0, feb:1, mar:2, apr:3, may:4, jun:5,
|
|
75
79
|
jul:6, aug:7, sep:8, oct:9, nov:10, dec:11
|
|
@@ -81,18 +85,19 @@ var NUM_TO_DAY = [
|
|
|
81
85
|
'Sun','Mon','Tue','Wed','Thu','Fri','Sat'
|
|
82
86
|
];
|
|
83
87
|
|
|
84
|
-
var YEAR = /^(
|
|
88
|
+
var YEAR = /^(\d{2}|\d{4})$/; // 2 to 4 digits
|
|
85
89
|
|
|
86
90
|
var MAX_TIME = 2147483647000; // 31-bit max
|
|
87
91
|
var MIN_TIME = 0; // 31-bit min
|
|
88
92
|
|
|
93
|
+
var cookiesCreated = 0; // Number of cookies created in runtime
|
|
94
|
+
|
|
89
95
|
|
|
90
96
|
// RFC6265 S5.1.1 date parser:
|
|
91
97
|
function parseDate(str,strict) {
|
|
92
98
|
if (!str) {
|
|
93
99
|
return;
|
|
94
100
|
}
|
|
95
|
-
var found_time, found_dom, found_month, found_year;
|
|
96
101
|
|
|
97
102
|
/* RFC6265 S5.1.1:
|
|
98
103
|
* 2. Process each date-token sequentially in the order the date-tokens
|
|
@@ -103,6 +108,13 @@ function parseDate(str,strict) {
|
|
|
103
108
|
return;
|
|
104
109
|
}
|
|
105
110
|
|
|
111
|
+
var hour = null;
|
|
112
|
+
var minutes = null;
|
|
113
|
+
var seconds = null;
|
|
114
|
+
var day = null;
|
|
115
|
+
var month = null;
|
|
116
|
+
var year = null;
|
|
117
|
+
|
|
106
118
|
var date = new Date();
|
|
107
119
|
date.setMilliseconds(0);
|
|
108
120
|
|
|
@@ -120,13 +132,22 @@ function parseDate(str,strict) {
|
|
|
120
132
|
* the date-token, respectively. Skip the remaining sub-steps and continue
|
|
121
133
|
* to the next date-token.
|
|
122
134
|
*/
|
|
123
|
-
if (
|
|
124
|
-
result =
|
|
135
|
+
if (seconds === null) {
|
|
136
|
+
result = TIME.exec(token);
|
|
125
137
|
if (result) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
hour = parseInt(result[1], 10);
|
|
139
|
+
minutes = parseInt(result[2], 10);
|
|
140
|
+
seconds = parseInt(result[3], 10);
|
|
141
|
+
/* RFC6265 S5.1.1.5:
|
|
142
|
+
* [fail if]
|
|
143
|
+
* * the hour-value is greater than 23,
|
|
144
|
+
* * the minute-value is greater than 59, or
|
|
145
|
+
* * the second-value is greater than 59.
|
|
146
|
+
*/
|
|
147
|
+
if(hour > 23 || minutes > 59 || seconds > 59) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
130
151
|
continue;
|
|
131
152
|
}
|
|
132
153
|
}
|
|
@@ -136,11 +157,16 @@ function parseDate(str,strict) {
|
|
|
136
157
|
* the day-of-month-value to the number denoted by the date-token. Skip
|
|
137
158
|
* the remaining sub-steps and continue to the next date-token.
|
|
138
159
|
*/
|
|
139
|
-
if (
|
|
160
|
+
if (day === null) {
|
|
140
161
|
result = DAY_OF_MONTH.exec(token);
|
|
141
162
|
if (result) {
|
|
142
|
-
|
|
143
|
-
|
|
163
|
+
day = parseInt(result, 10);
|
|
164
|
+
/* RFC6265 S5.1.1.5:
|
|
165
|
+
* [fail if] the day-of-month-value is less than 1 or greater than 31
|
|
166
|
+
*/
|
|
167
|
+
if(day < 1 || day > 31) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
144
170
|
continue;
|
|
145
171
|
}
|
|
146
172
|
}
|
|
@@ -150,11 +176,10 @@ function parseDate(str,strict) {
|
|
|
150
176
|
* the month denoted by the date-token. Skip the remaining sub-steps and
|
|
151
177
|
* continue to the next date-token.
|
|
152
178
|
*/
|
|
153
|
-
if (
|
|
179
|
+
if (month === null) {
|
|
154
180
|
result = MONTH.exec(token);
|
|
155
181
|
if (result) {
|
|
156
|
-
|
|
157
|
-
date.setUTCMonth(MONTH_TO_NUM[result[1].toLowerCase()]);
|
|
182
|
+
month = MONTH_TO_NUM[result[1].toLowerCase()];
|
|
158
183
|
continue;
|
|
159
184
|
}
|
|
160
185
|
}
|
|
@@ -164,10 +189,10 @@ function parseDate(str,strict) {
|
|
|
164
189
|
* denoted by the date-token. Skip the remaining sub-steps and continue to
|
|
165
190
|
* the next date-token.
|
|
166
191
|
*/
|
|
167
|
-
if (
|
|
192
|
+
if (year === null) {
|
|
168
193
|
result = YEAR.exec(token);
|
|
169
194
|
if (result) {
|
|
170
|
-
|
|
195
|
+
year = parseInt(result[0], 10);
|
|
171
196
|
/* From S5.1.1:
|
|
172
197
|
* 3. If the year-value is greater than or equal to 70 and less
|
|
173
198
|
* than or equal to 99, increment the year-value by 1900.
|
|
@@ -183,20 +208,17 @@ function parseDate(str,strict) {
|
|
|
183
208
|
if (year < 1601) {
|
|
184
209
|
return; // 5. ... the year-value is less than 1601
|
|
185
210
|
}
|
|
186
|
-
|
|
187
|
-
found_year = true;
|
|
188
|
-
date.setUTCFullYear(year);
|
|
189
211
|
continue;
|
|
190
212
|
}
|
|
191
213
|
}
|
|
192
214
|
}
|
|
193
215
|
|
|
194
|
-
if (
|
|
216
|
+
if (seconds === null || day === null || month === null || year === null) {
|
|
195
217
|
return; // 5. ... at least one of the found-day-of-month, found-month, found-
|
|
196
218
|
// year, or found-time flags is not set,
|
|
197
219
|
}
|
|
198
220
|
|
|
199
|
-
return
|
|
221
|
+
return new Date(Date.UTC(year, month, day, hour, minutes, seconds));
|
|
200
222
|
}
|
|
201
223
|
|
|
202
224
|
function formatDate(date) {
|
|
@@ -358,7 +380,9 @@ function parse(str, strict) {
|
|
|
358
380
|
|
|
359
381
|
var c = new Cookie();
|
|
360
382
|
c.key = result[1]; // the regexp should trim() already
|
|
361
|
-
c.value = result[3]; // [2] is quotes or empty-string
|
|
383
|
+
c.value = strict ? result[3] : result[2]; // [2] is quotes or empty-string in strict mode
|
|
384
|
+
c.key = c.key.trim();
|
|
385
|
+
c.value = c.value.trim();
|
|
362
386
|
|
|
363
387
|
if (firstSemi === -1) {
|
|
364
388
|
return c;
|
|
@@ -457,6 +481,7 @@ function parse(str, strict) {
|
|
|
457
481
|
* context of the parsing.
|
|
458
482
|
*/
|
|
459
483
|
if (!av_value || av_value.substr(0,1) != "/") {
|
|
484
|
+
c.path = null;
|
|
460
485
|
if(strict){return;}else{break;}
|
|
461
486
|
}
|
|
462
487
|
c.path = av_value;
|
|
@@ -486,6 +511,10 @@ function parse(str, strict) {
|
|
|
486
511
|
|
|
487
512
|
// ensure a default date for sorting:
|
|
488
513
|
c.creation = new Date();
|
|
514
|
+
//NOTE: add runtime index for the cookieCompare() to resolve the situation when Date's precision is not enough .
|
|
515
|
+
//Store initial UTC time as well, so we will be able to determine if we need to fallback to the Date object.
|
|
516
|
+
c._creationRuntimeIdx = ++cookiesCreated;
|
|
517
|
+
c._initialCreationTime = c.creation.getTime();
|
|
489
518
|
return c;
|
|
490
519
|
}
|
|
491
520
|
|
|
@@ -539,9 +568,18 @@ function cookieCompare(a,b) {
|
|
|
539
568
|
if (deltaLen !== 0) {
|
|
540
569
|
return deltaLen;
|
|
541
570
|
}
|
|
571
|
+
|
|
572
|
+
var aTime = a.creation ? a.creation.getTime() : MAX_TIME;
|
|
573
|
+
var bTime = b.creation ? b.creation.getTime() : MAX_TIME;
|
|
574
|
+
|
|
575
|
+
// NOTE: if creation dates are equal and they were not modified from the outside,
|
|
576
|
+
// then use _creationRuntimeIdx for the comparison.
|
|
577
|
+
if(aTime === bTime && aTime === a._initialCreationTime && bTime === b._initialCreationTime) {
|
|
578
|
+
return a._creationRuntimeIdx - b._creationRuntimeIdx;
|
|
579
|
+
}
|
|
580
|
+
|
|
542
581
|
// ascending for time: a CMP b
|
|
543
|
-
return
|
|
544
|
-
(b.creation ? b.creation.getTime() : MAX_TIME);
|
|
582
|
+
return aTime - bTime;
|
|
545
583
|
}
|
|
546
584
|
|
|
547
585
|
// Gives the permutation of all possible domainMatch()es of a given domain. The
|
|
@@ -588,6 +626,9 @@ function permutePath(path) {
|
|
|
588
626
|
return permutations;
|
|
589
627
|
}
|
|
590
628
|
|
|
629
|
+
function getCookieContext(url) {
|
|
630
|
+
return (url instanceof Object) ? url : urlParse(decodeURI(url));
|
|
631
|
+
}
|
|
591
632
|
|
|
592
633
|
function Cookie (opts) {
|
|
593
634
|
if (typeof opts !== "object") {
|
|
@@ -619,6 +660,8 @@ Cookie.prototype.extensions = null;
|
|
|
619
660
|
Cookie.prototype.hostOnly = null; // boolean when set
|
|
620
661
|
Cookie.prototype.pathIsDefault = null; // boolean when set
|
|
621
662
|
Cookie.prototype.creation = null; // Date when set; defaulted by Cookie.parse
|
|
663
|
+
Cookie.prototype._initialCreationTime = null; // Used to determine if cookie.creation was modified
|
|
664
|
+
Cookie.prototype._creationRuntimeIdx = null; // Runtime index of the created cookie, used in cookieCompare()
|
|
622
665
|
Cookie.prototype.lastAccessed = null; // Date when set
|
|
623
666
|
|
|
624
667
|
var cookieProperties = Object.freeze(Object.keys(Cookie.prototype).map(function(p) {
|
|
@@ -820,7 +863,7 @@ var CAN_BE_SYNC = [];
|
|
|
820
863
|
CAN_BE_SYNC.push('setCookie');
|
|
821
864
|
CookieJar.prototype.setCookie = function(cookie, url, options, cb) {
|
|
822
865
|
var err;
|
|
823
|
-
var context = (url
|
|
866
|
+
var context = getCookieContext(url);
|
|
824
867
|
if (options instanceof Function) {
|
|
825
868
|
cb = options;
|
|
826
869
|
options = {};
|
|
@@ -869,15 +912,12 @@ CookieJar.prototype.setCookie = function(cookie, url, options, cb) {
|
|
|
869
912
|
cookie.domain = host;
|
|
870
913
|
}
|
|
871
914
|
|
|
872
|
-
//
|
|
873
|
-
//
|
|
874
|
-
|
|
915
|
+
//S5.2.4 If the attribute-value is empty or if the first character of the
|
|
916
|
+
//attribute-value is not %x2F ("/"):
|
|
917
|
+
//Let cookie-path be the default-path.
|
|
918
|
+
if (!cookie.path || cookie.path[0] !== '/') {
|
|
875
919
|
cookie.path = defaultPath(context.pathname);
|
|
876
920
|
cookie.pathIsDefault = true;
|
|
877
|
-
} else {
|
|
878
|
-
if (cookie.path.length > 1 && cookie.path.substr(-1) == '/') {
|
|
879
|
-
cookie.path = cookie.path.slice(0,-1);
|
|
880
|
-
}
|
|
881
921
|
}
|
|
882
922
|
|
|
883
923
|
// S5.3 step 8: NOOP; secure attribute
|
|
@@ -934,7 +974,7 @@ CookieJar.prototype.setCookie = function(cookie, url, options, cb) {
|
|
|
934
974
|
// RFC6365 S5.4
|
|
935
975
|
CAN_BE_SYNC.push('getCookies');
|
|
936
976
|
CookieJar.prototype.getCookies = function(url, options, cb) {
|
|
937
|
-
var context = (url
|
|
977
|
+
var context = getCookieContext(url);
|
|
938
978
|
if (options instanceof Function) {
|
|
939
979
|
cb = options;
|
|
940
980
|
options = {};
|
|
@@ -1035,9 +1075,12 @@ CookieJar.prototype.getCookieString = function(/*..., cb*/) {
|
|
|
1035
1075
|
if (err) {
|
|
1036
1076
|
cb(err);
|
|
1037
1077
|
} else {
|
|
1038
|
-
cb(null, cookies
|
|
1039
|
-
|
|
1040
|
-
|
|
1078
|
+
cb(null, cookies
|
|
1079
|
+
.sort(cookieCompare)
|
|
1080
|
+
.map(function(c){
|
|
1081
|
+
return c.cookieString();
|
|
1082
|
+
})
|
|
1083
|
+
.join('; '));
|
|
1041
1084
|
}
|
|
1042
1085
|
};
|
|
1043
1086
|
args.push(next);
|