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 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
@@ -1,3 +1,4 @@
1
+ .idea
1
2
  node_modules/
2
3
  .*.sw[nmop]
3
4
  npm-debug.log
package/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  language: node_js
2
2
  node_js:
3
3
  - "0.10"
4
- - "0.11"
4
+ - "0.12"
5
+ - iojs
5
6
  matrix:
6
7
  fast_finish: true
7
8
  allow_failures:
package/LICENSE CHANGED
@@ -1,21 +1,17 @@
1
- Copyright GoInstant, Inc. and other contributors. All rights reserved.
2
- Permission is hereby granted, free of charge, to any person obtaining a copy
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
- The above copyright notice and this permission notice shall be included in
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
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
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](http://tools.ietf.org/html/rfc6265) Cookies and CookieJar for Node.js
1
+ [RFC6265](https://tools.ietf.org/html/rfc6265) Cookies and CookieJar for Node.js
2
2
 
3
- ![Tough Cookie](http://www.goinstant.com.s3.amazonaws.com/tough-cookie.jpg)
4
-
5
- [![Build Status](https://travis-ci.org/goinstant/node-cookie.png?branch=master)](https://travis-ci.org/goinstant/node-cookie)
3
+ [![Build Status](https://travis-ci.org/SalesforceEng/tough-cookie.png?branch=master)](https://travis-ci.org/SalesforceEng/tough-cookie)
6
4
 
7
5
  [![NPM Stats](https://nodei.co/npm/tough-cookie.png?downloads=true&stars=true)](https://npmjs.org/package/tough-cookie)
8
6
  ![NPM Downloads](https://nodei.co/npm-dl/tough-cookie.png?months=9)
@@ -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
- parseDate(string[,strict])
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()`. If strict is set to true then leading/trailing non-seperator characters around the time part will cause the parsing to fail (e.g. "Thu, 01 Jan 1970 00:00:010 GMT" has an extra trailing zero but Chrome, an assumedly RFC-compliant browser, treats this as valid).
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[,strict=false])
78
+ parse(header)
81
79
  ----------------------------
82
80
 
83
- alias for `Cookie.parse(header[,strict])`
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[,strict=false])
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. If in strict mode, returns `undefined` if the cookie doesn't follow the guidelines in section 4 of RFC6265. Generally speaking, strict mode can be used to validate your own generated Set-Cookie headers, but acting as a client you want to be lenient and leave strict mode off.
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` 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.
380
377
 
381
378
  Pass an error ONLY if removing any existing cookies failed.
382
379
 
383
- # TODO
380
+ MemoryCookieStore
381
+ =================
384
382
 
385
- * _full_ RFC5890/RFC5891 canonicalization for domains in `cdomain()`
386
- * the optional `punycode` requirement implements RFC3492, but RFC6265 requires RFC5891
387
- * better tests for `validate()`?
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: MIT with some MPL/1.1)
392
-
393
- Copyright 2012- GoInstant, Inc. and other contributors. All rights reserved.
394
- Permission is hereby granted, free of charge, to any person obtaining a copy
395
- of this software and associated documentation files (the "Software"), to
396
- deal in the Software without restriction, including without limitation the
397
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
398
- sell copies of the Software, and to permit persons to whom the Software is
399
- furnished to do so, subject to the following conditions:
400
-
401
- The above copyright notice and this permission notice shall be included in
402
- all copies or substantial portions of the Software.
403
-
404
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
405
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
406
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
407
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
408
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
409
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
410
- IN THE SOFTWARE.
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.
@@ -1,22 +1,32 @@
1
- /*
2
- * Copyright GoInstant, Inc. and other contributors. All rights reserved.
3
- * Permission is hereby granted, free of charge, to any person obtaining a copy
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
- * The above copyright notice and this permission notice shall be included in
11
- * all copies or substantial portions of the Software.
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
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
- * IN THE SOFTWARE.
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 GoInstant, Inc. and other contributors. All rights reserved.
95
- * Permission is hereby granted, free of charge, to any person obtaining a copy
96
- * of this software and associated documentation files (the "Software"), to
97
- * deal in the Software without restriction, including without limitation the
98
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
99
- * sell copies of the Software, and to permit persons to whom the Software is
100
- * furnished to do so, subject to the following conditions:
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
- * The above copyright notice and this permission notice shall be included in
103
- * all copies or substantial portions of the Software.
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
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
106
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
107
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
108
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
109
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
110
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
111
- * IN THE SOFTWARE.
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 = '.'+part+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
- if (suffixLen && parts.length > suffixLen) {
147
- return parts.slice(0,suffixLen+1).reverse().join('.');
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://publicsuffix.org/list/test.txt
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', null);
178
- checkPublicSuffix('b.example.example', null);
179
- checkPublicSuffix('a.b.example.example', null);
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('c.kyoto.jp', null);
214
- checkPublicSuffix('b.c.kyoto.jp', 'b.c.kyoto.jp');
215
- checkPublicSuffix('a.b.c.kyoto.jp', 'b.c.kyoto.jp');
216
- checkPublicSuffix('pref.kyoto.jp', 'pref.kyoto.jp'); // Exception rule.
217
- checkPublicSuffix('www.pref.kyoto.jp', 'pref.kyoto.jp'); // Exception rule.
218
- checkPublicSuffix('city.kyoto.jp', 'city.kyoto.jp'); // Exception rule.
219
- checkPublicSuffix('www.city.kyoto.jp', 'city.kyoto.jp'); // Exception rule.
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('om', null);
222
- checkPublicSuffix('test.om', null);
223
- checkPublicSuffix('b.test.om', 'b.test.om');
224
- checkPublicSuffix('a.b.test.om', 'b.test.om');
225
- checkPublicSuffix('songfest.om', 'songfest.om');
226
- checkPublicSuffix('www.songfest.om', 'songfest.om');
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
  }