tough-cookie 0.10.0 → 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/.jshintrc +54 -56
- package/.npmignore +1 -0
- package/.travis.yml +2 -1
- package/LICENSE +22 -26
- package/README.md +65 -26
- package/generate-pubsuffix.js +72 -43
- package/lib/cookie.js +370 -164
- package/lib/memstore.js +73 -32
- package/lib/pubsuffix.js +27 -17
- package/lib/store.js +67 -0
- package/package.json +7 -7
- 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 -1411
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/.jshintrc
CHANGED
|
@@ -1,72 +1,70 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
"
|
|
4
|
-
"maxerr" : 100, // Maximum error before stopping.
|
|
2
|
+
"passfail" : false,
|
|
3
|
+
"maxerr" : 100,
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
// Predefined globals whom JSHint will ignore.
|
|
8
|
-
"browser" : false, // Standard browser globals e.g. `window`, `document`.
|
|
5
|
+
"browser" : false,
|
|
9
6
|
"node" : true,
|
|
10
7
|
"rhino" : false,
|
|
11
8
|
"couch" : false,
|
|
12
|
-
"wsh" : false,
|
|
9
|
+
"wsh" : false,
|
|
13
10
|
|
|
14
11
|
"jquery" : false,
|
|
15
12
|
"prototypejs" : false,
|
|
16
13
|
"mootools" : false,
|
|
17
14
|
"dojo" : false,
|
|
18
15
|
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
],
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
// Development.
|
|
25
|
-
"debug" : false, // Allow debugger statements e.g. browser breakpoints.
|
|
26
|
-
"devel" : false, // Allow developments statements e.g. `console.log();`.
|
|
16
|
+
"debug" : false,
|
|
17
|
+
"devel" : false,
|
|
27
18
|
|
|
19
|
+
"esnext" : true,
|
|
20
|
+
"strict" : true,
|
|
21
|
+
"globalstrict" : true,
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
23
|
+
"asi" : false,
|
|
24
|
+
"laxbreak" : false,
|
|
25
|
+
"bitwise" : true,
|
|
26
|
+
"boss" : false,
|
|
27
|
+
"curly" : true,
|
|
28
|
+
"eqeqeq" : false,
|
|
29
|
+
"eqnull" : true,
|
|
30
|
+
"evil" : false,
|
|
31
|
+
"expr" : false,
|
|
32
|
+
"forin" : false,
|
|
33
|
+
"immed" : true,
|
|
34
|
+
"lastsemic" : true,
|
|
35
|
+
"latedef" : false,
|
|
36
|
+
"loopfunc" : false,
|
|
37
|
+
"noarg" : true,
|
|
38
|
+
"regexp" : false,
|
|
39
|
+
"regexdash" : false,
|
|
40
|
+
"scripturl" : false,
|
|
41
|
+
"shadow" : false,
|
|
42
|
+
"supernew" : false,
|
|
43
|
+
"undef" : true,
|
|
44
|
+
"unused" : true,
|
|
34
45
|
|
|
46
|
+
"newcap" : true,
|
|
47
|
+
"noempty" : true,
|
|
48
|
+
"nonew" : true,
|
|
49
|
+
"nomen" : false,
|
|
50
|
+
"onevar" : false,
|
|
51
|
+
"onecase" : true,
|
|
52
|
+
"plusplus" : false,
|
|
53
|
+
"proto" : false,
|
|
54
|
+
"sub" : true,
|
|
55
|
+
"trailing" : true,
|
|
56
|
+
"white" : false,
|
|
35
57
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
"latedef" : false, // Prohibit variable use before definition.
|
|
49
|
-
"loopfunc" : false, // Allow functions to be defined within loops.
|
|
50
|
-
"noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
|
|
51
|
-
"regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
|
|
52
|
-
"regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
|
|
53
|
-
"scripturl" : true, // Tolerate script-targeted URLs.
|
|
54
|
-
"shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
|
|
55
|
-
"supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
|
|
56
|
-
"undef" : true, // Require all non-global variables be declared before they are used.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// Personal styling prefrences.
|
|
60
|
-
"lastsemic" : true, // Prohibit missing semicolon for the last statement in a one-line block
|
|
61
|
-
"newcap" : false, // Require capitalization of all constructor functions e.g. `new F()`.
|
|
62
|
-
"noempty" : true, // Prohipit use of empty blocks.
|
|
63
|
-
"nonew" : true, // Prohibit use of constructors for side-effects.
|
|
64
|
-
"nomen" : false, // Prohibit use of initial or trailing underbars in names.
|
|
65
|
-
"onevar" : false, // Allow only one `var` statement per function.
|
|
66
|
-
"onecase" : false, // Allow switches with one case statement
|
|
67
|
-
"plusplus" : false, // Prohibit use of `++` & `--`.
|
|
68
|
-
"proto" : false, // Allow use of __proto__
|
|
69
|
-
"sub" : true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
|
|
70
|
-
"trailing" : true, // Prohibit trailing whitespaces.
|
|
71
|
-
"white" : false // Check against strict whitespace and indentation rules.
|
|
58
|
+
"predef": [
|
|
59
|
+
"describe",
|
|
60
|
+
"it",
|
|
61
|
+
"before",
|
|
62
|
+
"beforeEach",
|
|
63
|
+
"after",
|
|
64
|
+
"afterEach",
|
|
65
|
+
"expect",
|
|
66
|
+
"setTimeout",
|
|
67
|
+
"clearTimeout"
|
|
68
|
+
],
|
|
69
|
+
"maxlen": 0
|
|
72
70
|
}
|
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
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
# Synopsis
|
|
11
11
|
|
|
12
12
|
``` javascript
|
|
13
|
-
var
|
|
14
|
-
var Cookie =
|
|
13
|
+
var tough = require('tough-cookie'); // note: not 'cookie', 'cookies' or 'node-cookie'
|
|
14
|
+
var Cookie = tough.Cookie;
|
|
15
15
|
var cookie = Cookie.parse(header);
|
|
16
16
|
cookie.value = 'somethingdifferent';
|
|
17
17
|
header = cookie.toString();
|
|
18
18
|
|
|
19
|
-
var cookiejar = new
|
|
19
|
+
var cookiejar = new tough.CookieJar();
|
|
20
20
|
cookiejar.setCookie(cookie, 'http://currentdomain.example.com/path', cb);
|
|
21
21
|
// ...
|
|
22
22
|
cookiejar.getCookies('http://example.com/otherpath',function(err,cookies) {
|
|
@@ -36,8 +36,8 @@ Why the name? NPM modules `cookie`, `cookies` and `cookiejar` were already take
|
|
|
36
36
|
|
|
37
37
|
# API
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
tough
|
|
40
|
+
=====
|
|
41
41
|
|
|
42
42
|
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
43
|
|
|
@@ -259,6 +259,11 @@ The `options` object can be omitted and can have the following properties:
|
|
|
259
259
|
|
|
260
260
|
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).
|
|
261
261
|
|
|
262
|
+
.setCookieSync(cookieOrString, currentUrl, [{options}])
|
|
263
|
+
-------------------------------------------------------
|
|
264
|
+
|
|
265
|
+
Synchronous version of `setCookie`; only works with synchronous stores (e.g. the default `MemoryCookieStore`).
|
|
266
|
+
|
|
262
267
|
.storeCookie(cookie, [{options},] cb(err,cookie))
|
|
263
268
|
-------------------------------------------------
|
|
264
269
|
|
|
@@ -281,20 +286,42 @@ The `options` object can be omitted and can have the following properties:
|
|
|
281
286
|
|
|
282
287
|
The `.lastAccessed` property of the returned cookies will have been updated.
|
|
283
288
|
|
|
289
|
+
.getCookiesSync(currentUrl, [{options}])
|
|
290
|
+
----------------------------------------
|
|
291
|
+
|
|
292
|
+
Synchronous version of `getCookies`; only works with synchronous stores (e.g. the default `MemoryCookieStore`).
|
|
293
|
+
|
|
284
294
|
.getCookieString(...)
|
|
285
295
|
---------------------
|
|
286
296
|
|
|
287
297
|
Accepts the same options as `.getCookies()` but passes a string suitable for a Cookie header rather than an array to the callback. Simply maps the `Cookie` array via `.cookieString()`.
|
|
288
298
|
|
|
299
|
+
.getCookieStringSync(...)
|
|
300
|
+
-------------------------
|
|
301
|
+
|
|
302
|
+
Synchronous version of `getCookieString`; only works with synchronous stores (e.g. the default `MemoryCookieStore`).
|
|
303
|
+
|
|
289
304
|
.getSetCookieStrings(...)
|
|
290
305
|
-------------------------
|
|
291
306
|
|
|
292
|
-
|
|
307
|
+
Returns an array of strings suitable for **Set-Cookie** headers. Accepts the same options as `.getCookies()`. Simply maps the cookie array via `.toString()`.
|
|
308
|
+
|
|
309
|
+
.getSetCookieStringsSync(...)
|
|
310
|
+
-----------------------------
|
|
311
|
+
|
|
312
|
+
Synchronous version of `getSetCookieStrings`; only works with synchronous stores (e.g. the default `MemoryCookieStore`).
|
|
313
|
+
|
|
314
|
+
Store
|
|
315
|
+
=====
|
|
316
|
+
|
|
317
|
+
Base class for CookieJar stores.
|
|
293
318
|
|
|
294
319
|
# CookieStore API
|
|
295
320
|
|
|
296
321
|
The storage model for each `CookieJar` instance can be replaced with a custom implementation. The default is `MemoryCookieStore` which can be found in the `lib/memstore.js` file. The API uses continuation-passing-style to allow for asynchronous stores.
|
|
297
322
|
|
|
323
|
+
Stores should inherit from the base `Store` class, which is available as `require('tough-cookie').Store`. Stores are asynchronous by default, but if `store.synchronous` is set, then the `*Sync` methods on the CookieJar can be used.
|
|
324
|
+
|
|
298
325
|
All `domain` parameters will have been normalized before calling.
|
|
299
326
|
|
|
300
327
|
The Cookie store must have all of the following methods.
|
|
@@ -361,25 +388,37 @@ Pass an error ONLY if removing any existing cookies failed.
|
|
|
361
388
|
|
|
362
389
|
# Copyright and License
|
|
363
390
|
|
|
364
|
-
(tl;dr:
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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
|
+
```
|
|
384
423
|
|
|
385
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,30 +1,42 @@
|
|
|
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');
|
|
23
33
|
var assert = require('assert');
|
|
24
34
|
var punycode = require('punycode');
|
|
25
35
|
|
|
26
36
|
fs.readFile('./public-suffix.txt', 'utf8', function(err,string) {
|
|
27
|
-
if (err)
|
|
37
|
+
if (err) {
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
28
40
|
var lines = string.split("\n");
|
|
29
41
|
process.nextTick(function() {
|
|
30
42
|
processList(lines);
|
|
@@ -38,7 +50,9 @@ function processList(lines) {
|
|
|
38
50
|
while (lines.length) {
|
|
39
51
|
var line = lines.shift();
|
|
40
52
|
line = line.replace(COMMENT,'').trim();
|
|
41
|
-
if (!line)
|
|
53
|
+
if (!line) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
42
56
|
addToIndex(index,line);
|
|
43
57
|
}
|
|
44
58
|
|
|
@@ -47,7 +61,7 @@ function processList(lines) {
|
|
|
47
61
|
var w = fs.createWriteStream('./lib/pubsuffix.js',{
|
|
48
62
|
flags: 'w',
|
|
49
63
|
encoding: 'utf8',
|
|
50
|
-
mode:
|
|
64
|
+
mode: parseInt('644',8)
|
|
51
65
|
});
|
|
52
66
|
w.on('end', process.exit);
|
|
53
67
|
w.write("/****************************************************\n");
|
|
@@ -76,37 +90,52 @@ function addToIndex(index,line) {
|
|
|
76
90
|
line = line.slice(prefix.length);
|
|
77
91
|
}
|
|
78
92
|
line = prefix + punycode.toASCII(line);
|
|
79
|
-
|
|
80
|
-
if (line.substr(0,1) == '!')
|
|
93
|
+
|
|
94
|
+
if (line.substr(0,1) == '!') {
|
|
81
95
|
index[line.substr(1)] = false;
|
|
82
|
-
else
|
|
96
|
+
} else {
|
|
83
97
|
index[line] = true;
|
|
98
|
+
}
|
|
84
99
|
}
|
|
85
100
|
|
|
86
101
|
// include the licence in the function since it gets written to pubsuffix.js
|
|
87
102
|
function getPublicSuffix(domain) {
|
|
88
|
-
|
|
89
|
-
* Copyright
|
|
90
|
-
*
|
|
91
|
-
* of this software and associated documentation files (the "Software"), to
|
|
92
|
-
* deal in the Software without restriction, including without limitation the
|
|
93
|
-
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
94
|
-
* sell copies of the Software, and to permit persons to whom the Software is
|
|
95
|
-
* furnished to do so, subject to the following conditions:
|
|
103
|
+
/*!
|
|
104
|
+
* Copyright (c) 2015, Salesforce.com, Inc.
|
|
105
|
+
* All rights reserved.
|
|
96
106
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
107
|
+
* Redistribution and use in source and binary forms, with or without
|
|
108
|
+
* modification, are permitted provided that the following conditions are met:
|
|
99
109
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
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.
|
|
116
|
+
*
|
|
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.
|
|
120
|
+
*
|
|
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.
|
|
107
132
|
*/
|
|
108
|
-
if (!domain)
|
|
109
|
-
|
|
133
|
+
if (!domain) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
if (domain.match(/^\./)) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
110
139
|
|
|
111
140
|
domain = domain.toLowerCase();
|
|
112
141
|
var parts = domain.split('.').reverse();
|