tough-cookie 0.12.1 → 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/.editorconfig +12 -0
- package/.npmignore +1 -0
- package/.travis.yml +2 -1
- package/LICENSE +22 -26
- package/README.md +48 -38
- package/generate-pubsuffix.js +114 -60
- package/lib/cookie.js +163 -182
- package/lib/memstore.js +45 -26
- package/lib/pathMatch.js +61 -0
- package/lib/permuteDomain.js +56 -0
- package/lib/pubsuffix.js +52 -23
- package/lib/store.js +30 -0
- package/package.json +8 -11
- package/public-suffix.txt +5511 -661
- package/test/api_test.js +372 -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 +294 -0
- package/test/regression_test.js +143 -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
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
[RFC6265](
|
|
1
|
+
[RFC6265](https://tools.ietf.org/html/rfc6265) Cookies and CookieJar for Node.js
|
|
2
2
|
|
|
3
|
-
](https://travis-ci.org/goinstant/node-cookie)
|
|
3
|
+
[](https://travis-ci.org/SalesforceEng/tough-cookie)
|
|
6
4
|
|
|
7
5
|
[](https://npmjs.org/package/tough-cookie)
|
|
8
6
|

|
|
@@ -30,8 +28,6 @@ It's _so_ easy!
|
|
|
30
28
|
|
|
31
29
|
`npm install tough-cookie`
|
|
32
30
|
|
|
33
|
-
Requires `punycode`, which should get installed automatically for you. Note that node.js v0.6.2+ bundles punycode by default.
|
|
34
|
-
|
|
35
31
|
Why the name? NPM modules `cookie`, `cookies` and `cookiejar` were already taken.
|
|
36
32
|
|
|
37
33
|
# API
|
|
@@ -41,10 +37,12 @@ tough
|
|
|
41
37
|
|
|
42
38
|
Functions on the module you get from `require('tough-cookie')`. All can be used as pure functions and don't need to be "bound".
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
**Note**: prior to 1.0.x, several of these functions took a `strict` parameter. This has since been removed from the API as it was no longer necessary.
|
|
41
|
+
|
|
42
|
+
parseDate(string)
|
|
45
43
|
-----------------
|
|
46
44
|
|
|
47
|
-
Parse a cookie date string into a `Date`. Parses according to RFC6265 Section 5.1.1, not `Date.parse()`.
|
|
45
|
+
Parse a cookie date string into a `Date`. Parses according to RFC6265 Section 5.1.1, not `Date.parse()`.
|
|
48
46
|
|
|
49
47
|
formatDate(date)
|
|
50
48
|
----------------
|
|
@@ -77,10 +75,10 @@ Answers "does the request-path path-match a given cookie-path?" as per RFC6265 S
|
|
|
77
75
|
|
|
78
76
|
This is essentially a prefix-match where `cookiePath` is a prefix of `reqPath`.
|
|
79
77
|
|
|
80
|
-
parse(header
|
|
78
|
+
parse(header)
|
|
81
79
|
----------------------------
|
|
82
80
|
|
|
83
|
-
alias for `Cookie.parse(header
|
|
81
|
+
alias for `Cookie.parse(header)`
|
|
84
82
|
|
|
85
83
|
fromJSON(string)
|
|
86
84
|
----------------
|
|
@@ -120,10 +118,10 @@ Generates a list of all possible paths that `pathMatch()` the parameter. May be
|
|
|
120
118
|
Cookie
|
|
121
119
|
======
|
|
122
120
|
|
|
123
|
-
Cookie.parse(header
|
|
121
|
+
Cookie.parse(header)
|
|
124
122
|
-----------------------------------
|
|
125
123
|
|
|
126
|
-
Parses a single Cookie or Set-Cookie HTTP header into a `Cookie` object. Returns `undefined` if the string can't be parsed.
|
|
124
|
+
Parses a single Cookie or Set-Cookie HTTP header into a `Cookie` object. Returns `undefined` if the string can't be parsed.
|
|
127
125
|
|
|
128
126
|
Here's how to process the Set-Cookie header(s) on a node HTTP/HTTPS response:
|
|
129
127
|
|
|
@@ -254,7 +252,6 @@ The `options` object can be omitted and can have the following properties:
|
|
|
254
252
|
* _http_ - boolean - default `true` - indicates if this is an HTTP or non-HTTP API. Affects HttpOnly cookies.
|
|
255
253
|
* _secure_ - boolean - autodetect from url - indicates if this is a "Secure" API. If the currentUrl starts with `https:` or `wss:` then this is defaulted to `true`, otherwise `false`.
|
|
256
254
|
* _now_ - Date - default `new Date()` - what to use for the creation/access time of cookies
|
|
257
|
-
* _strict_ - boolean - default `false` - perform extra checks
|
|
258
255
|
* _ignoreError_ - boolean - default `false` - silently ignore things like parse errors and invalid domains. CookieStore errors aren't ignored by this option.
|
|
259
256
|
|
|
260
257
|
As per the RFC, the `.hostOnly` property is set if there was no "Domain=" parameter in the cookie string (or `.domain` was null on the Cookie object). The `.domain` property is set to the fully-qualified hostname of `currentUrl` in this case. Matching this cookie requires an exact hostname match (not a `domainMatch` as per usual).
|
|
@@ -376,37 +373,50 @@ The implementation MUST NOT pass an error if the cookie doesn't exist; only pass
|
|
|
376
373
|
store.removeCookies(domain, path, cb(err))
|
|
377
374
|
------------------------------------------
|
|
378
375
|
|
|
379
|
-
Removes matching cookies from the store. The `path`
|
|
376
|
+
Removes matching cookies from the store. The `path` parameter is optional, and if missing means all paths in a domain should be removed.
|
|
380
377
|
|
|
381
378
|
Pass an error ONLY if removing any existing cookies failed.
|
|
382
379
|
|
|
383
|
-
|
|
380
|
+
MemoryCookieStore
|
|
381
|
+
=================
|
|
384
382
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
383
|
+
Inherits from Store.
|
|
384
|
+
|
|
385
|
+
Just-in-memory CookieJar synchronous store implementation, used by default.
|
|
388
386
|
|
|
389
387
|
# Copyright and License
|
|
390
388
|
|
|
391
|
-
(tl;dr:
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
389
|
+
(tl;dr: BSD-3-Clause with some MPL/1.1)
|
|
390
|
+
|
|
391
|
+
```text
|
|
392
|
+
Copyright (c) 2015, Salesforce.com, Inc.
|
|
393
|
+
All rights reserved.
|
|
394
|
+
|
|
395
|
+
Redistribution and use in source and binary forms, with or without
|
|
396
|
+
modification, are permitted provided that the following conditions are met:
|
|
397
|
+
|
|
398
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
399
|
+
this list of conditions and the following disclaimer.
|
|
400
|
+
|
|
401
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
402
|
+
this list of conditions and the following disclaimer in the documentation
|
|
403
|
+
and/or other materials provided with the distribution.
|
|
404
|
+
|
|
405
|
+
3. Neither the name of Salesforce.com nor the names of its contributors may
|
|
406
|
+
be used to endorse or promote products derived from this software without
|
|
407
|
+
specific prior written permission.
|
|
408
|
+
|
|
409
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
410
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
411
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
412
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
413
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
414
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
415
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
416
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
417
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
418
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
419
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
420
|
+
```
|
|
411
421
|
|
|
412
422
|
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');
|
|
@@ -59,6 +69,9 @@ function processList(lines) {
|
|
|
59
69
|
w.write(" * DO NOT EDIT! *\n");
|
|
60
70
|
w.write(" ****************************************************/\n\n");
|
|
61
71
|
|
|
72
|
+
w.write('"use strict";\n\n');
|
|
73
|
+
w.write("var punycode = require('punycode');\n\n");
|
|
74
|
+
|
|
62
75
|
w.write("module.exports.getPublicSuffix = ");
|
|
63
76
|
w.write(getPublicSuffix.toString());
|
|
64
77
|
w.write(";\n\n");
|
|
@@ -90,25 +103,35 @@ function addToIndex(index,line) {
|
|
|
90
103
|
|
|
91
104
|
// include the licence in the function since it gets written to pubsuffix.js
|
|
92
105
|
function getPublicSuffix(domain) {
|
|
93
|
-
|
|
94
|
-
* Copyright
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
106
|
+
/*!
|
|
107
|
+
* Copyright (c) 2015, Salesforce.com, Inc.
|
|
108
|
+
* All rights reserved.
|
|
109
|
+
*
|
|
110
|
+
* Redistribution and use in source and binary forms, with or without
|
|
111
|
+
* modification, are permitted provided that the following conditions are met:
|
|
112
|
+
*
|
|
113
|
+
* 1. Redistributions of source code must retain the above copyright notice,
|
|
114
|
+
* this list of conditions and the following disclaimer.
|
|
101
115
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
116
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
117
|
+
* this list of conditions and the following disclaimer in the documentation
|
|
118
|
+
* and/or other materials provided with the distribution.
|
|
104
119
|
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
120
|
+
* 3. Neither the name of Salesforce.com nor the names of its contributors may
|
|
121
|
+
* be used to endorse or promote products derived from this software without
|
|
122
|
+
* specific prior written permission.
|
|
123
|
+
*
|
|
124
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
125
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
126
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
127
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
128
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
129
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
130
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
131
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
132
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
133
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
134
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
112
135
|
*/
|
|
113
136
|
if (!domain) {
|
|
114
137
|
return null;
|
|
@@ -116,6 +139,15 @@ function getPublicSuffix(domain) {
|
|
|
116
139
|
if (domain.match(/^\./)) {
|
|
117
140
|
return null;
|
|
118
141
|
}
|
|
142
|
+
var asciiDomain = punycode.toASCII(domain);
|
|
143
|
+
var converted = false;
|
|
144
|
+
if (asciiDomain !== domain) {
|
|
145
|
+
domain = asciiDomain;
|
|
146
|
+
converted = true;
|
|
147
|
+
}
|
|
148
|
+
if (index[domain]) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
119
151
|
|
|
120
152
|
domain = domain.toLowerCase();
|
|
121
153
|
var parts = domain.split('.').reverse();
|
|
@@ -136,15 +168,17 @@ function getPublicSuffix(domain) {
|
|
|
136
168
|
suffixLen = i+1;
|
|
137
169
|
}
|
|
138
170
|
|
|
139
|
-
suffix = '.'+
|
|
171
|
+
suffix = '.'+partstr;
|
|
140
172
|
}
|
|
141
173
|
|
|
142
174
|
if (index['*'+suffix]) { // *.domain exists (e.g. *.kyoto.jp for domain='kyoto.jp');
|
|
143
175
|
return null;
|
|
144
176
|
}
|
|
145
177
|
|
|
146
|
-
|
|
147
|
-
|
|
178
|
+
suffixLen = suffixLen || 1;
|
|
179
|
+
if (parts.length > suffixLen) {
|
|
180
|
+
var publicSuffix = parts.slice(0,suffixLen+1).reverse().join('.');
|
|
181
|
+
return converted ? punycode.toUnicode(publicSuffix) : publicSuffix;
|
|
148
182
|
}
|
|
149
183
|
|
|
150
184
|
return null;
|
|
@@ -155,7 +189,7 @@ function checkPublicSuffix(give,get) {
|
|
|
155
189
|
assert.equal(got, get, give+' should be '+(get==null?'NULL':get)+' but got '+got);
|
|
156
190
|
}
|
|
157
191
|
|
|
158
|
-
// pubSufTest() was converted to JavaScript from http://
|
|
192
|
+
// pubSufTest() was converted to JavaScript from http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1
|
|
159
193
|
function pubSufTest() {
|
|
160
194
|
// For this function-scope and this function-scope ONLY:
|
|
161
195
|
// Any copyright is dedicated to the Public Domain.
|
|
@@ -174,14 +208,14 @@ function pubSufTest() {
|
|
|
174
208
|
checkPublicSuffix('.example.example', null);
|
|
175
209
|
// Unlisted TLD.
|
|
176
210
|
checkPublicSuffix('example', null);
|
|
177
|
-
checkPublicSuffix('example.example',
|
|
178
|
-
checkPublicSuffix('b.example.example',
|
|
179
|
-
checkPublicSuffix('a.b.example.example',
|
|
211
|
+
checkPublicSuffix('example.example', 'example.example');
|
|
212
|
+
checkPublicSuffix('b.example.example', 'example.example');
|
|
213
|
+
checkPublicSuffix('a.b.example.example', 'example.example');
|
|
180
214
|
// Listed, but non-Internet, TLD.
|
|
181
|
-
checkPublicSuffix('local', null);
|
|
182
|
-
checkPublicSuffix('example.local', null);
|
|
183
|
-
checkPublicSuffix('b.example.local', null);
|
|
184
|
-
checkPublicSuffix('a.b.example.local', null);
|
|
215
|
+
//checkPublicSuffix('local', null);
|
|
216
|
+
//checkPublicSuffix('example.local', null);
|
|
217
|
+
//checkPublicSuffix('b.example.local', null);
|
|
218
|
+
//checkPublicSuffix('a.b.example.local', null);
|
|
185
219
|
// TLD with only 1 rule.
|
|
186
220
|
checkPublicSuffix('biz', null);
|
|
187
221
|
checkPublicSuffix('domain.biz', 'domain.biz');
|
|
@@ -210,20 +244,22 @@ function pubSufTest() {
|
|
|
210
244
|
checkPublicSuffix('test.ac.jp', 'test.ac.jp');
|
|
211
245
|
checkPublicSuffix('www.test.ac.jp', 'test.ac.jp');
|
|
212
246
|
checkPublicSuffix('kyoto.jp', null);
|
|
213
|
-
checkPublicSuffix('
|
|
214
|
-
checkPublicSuffix('
|
|
215
|
-
checkPublicSuffix('
|
|
216
|
-
checkPublicSuffix('
|
|
217
|
-
checkPublicSuffix('
|
|
218
|
-
checkPublicSuffix('
|
|
219
|
-
checkPublicSuffix('
|
|
247
|
+
checkPublicSuffix('test.kyoto.jp', 'test.kyoto.jp');
|
|
248
|
+
checkPublicSuffix('ide.kyoto.jp', null);
|
|
249
|
+
checkPublicSuffix('b.ide.kyoto.jp', 'b.ide.kyoto.jp');
|
|
250
|
+
checkPublicSuffix('a.b.ide.kyoto.jp', 'b.ide.kyoto.jp');
|
|
251
|
+
checkPublicSuffix('c.kobe.jp', null);
|
|
252
|
+
checkPublicSuffix('b.c.kobe.jp', 'b.c.kobe.jp');
|
|
253
|
+
checkPublicSuffix('a.b.c.kobe.jp', 'b.c.kobe.jp');
|
|
254
|
+
checkPublicSuffix('city.kobe.jp', 'city.kobe.jp');
|
|
255
|
+
checkPublicSuffix('www.city.kobe.jp', 'city.kobe.jp');
|
|
220
256
|
// TLD with a wildcard rule and exceptions.
|
|
221
|
-
checkPublicSuffix('
|
|
222
|
-
checkPublicSuffix('test.
|
|
223
|
-
checkPublicSuffix('b.test.
|
|
224
|
-
checkPublicSuffix('a.b.test.
|
|
225
|
-
checkPublicSuffix('
|
|
226
|
-
checkPublicSuffix('www.
|
|
257
|
+
checkPublicSuffix('ck', null);
|
|
258
|
+
checkPublicSuffix('test.ck', null);
|
|
259
|
+
checkPublicSuffix('b.test.ck', 'b.test.ck');
|
|
260
|
+
checkPublicSuffix('a.b.test.ck', 'b.test.ck');
|
|
261
|
+
checkPublicSuffix('www.ck', 'www.ck');
|
|
262
|
+
checkPublicSuffix('www.www.ck', 'www.ck');
|
|
227
263
|
// US K12.
|
|
228
264
|
checkPublicSuffix('us', null);
|
|
229
265
|
checkPublicSuffix('test.us', 'test.us');
|
|
@@ -234,6 +270,24 @@ function pubSufTest() {
|
|
|
234
270
|
checkPublicSuffix('k12.ak.us', null);
|
|
235
271
|
checkPublicSuffix('test.k12.ak.us', 'test.k12.ak.us');
|
|
236
272
|
checkPublicSuffix('www.test.k12.ak.us', 'test.k12.ak.us');
|
|
237
|
-
|
|
238
|
-
|
|
273
|
+
// IDN labels.
|
|
274
|
+
checkPublicSuffix('食狮.com.cn', '食狮.com.cn');
|
|
275
|
+
checkPublicSuffix('食狮.公司.cn', '食狮.公司.cn');
|
|
276
|
+
checkPublicSuffix('www.食狮.公司.cn', '食狮.公司.cn');
|
|
277
|
+
checkPublicSuffix('shishi.公司.cn', 'shishi.公司.cn');
|
|
278
|
+
checkPublicSuffix('公司.cn', null);
|
|
279
|
+
checkPublicSuffix('食狮.中国', '食狮.中国');
|
|
280
|
+
checkPublicSuffix('www.食狮.中国', '食狮.中国');
|
|
281
|
+
checkPublicSuffix('shishi.中国', 'shishi.中国');
|
|
282
|
+
checkPublicSuffix('中国', null);
|
|
283
|
+
// Same as above, but punycoded.
|
|
284
|
+
checkPublicSuffix('xn--85x722f.com.cn', 'xn--85x722f.com.cn');
|
|
285
|
+
checkPublicSuffix('xn--85x722f.xn--55qx5d.cn', 'xn--85x722f.xn--55qx5d.cn');
|
|
286
|
+
checkPublicSuffix('www.xn--85x722f.xn--55qx5d.cn', 'xn--85x722f.xn--55qx5d.cn');
|
|
287
|
+
checkPublicSuffix('shishi.xn--55qx5d.cn', 'shishi.xn--55qx5d.cn');
|
|
288
|
+
checkPublicSuffix('xn--55qx5d.cn', null);
|
|
289
|
+
checkPublicSuffix('xn--85x722f.xn--fiqs8s', 'xn--85x722f.xn--fiqs8s');
|
|
290
|
+
checkPublicSuffix('www.xn--85x722f.xn--fiqs8s', 'xn--85x722f.xn--fiqs8s');
|
|
291
|
+
checkPublicSuffix('shishi.xn--fiqs8s', 'shishi.xn--fiqs8s');
|
|
292
|
+
checkPublicSuffix('xn--fiqs8s', null);
|
|
239
293
|
}
|