tough-cookie 0.13.0 → 2.0.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.
@@ -69,6 +69,9 @@ function processList(lines) {
69
69
  w.write(" * DO NOT EDIT! *\n");
70
70
  w.write(" ****************************************************/\n\n");
71
71
 
72
+ w.write('"use strict";\n\n');
73
+ w.write("var punycode = require('punycode');\n\n");
74
+
72
75
  w.write("module.exports.getPublicSuffix = ");
73
76
  w.write(getPublicSuffix.toString());
74
77
  w.write(";\n\n");
@@ -136,6 +139,15 @@ function getPublicSuffix(domain) {
136
139
  if (domain.match(/^\./)) {
137
140
  return null;
138
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
+ }
139
151
 
140
152
  domain = domain.toLowerCase();
141
153
  var parts = domain.split('.').reverse();
@@ -156,15 +168,17 @@ function getPublicSuffix(domain) {
156
168
  suffixLen = i+1;
157
169
  }
158
170
 
159
- suffix = '.'+part+suffix;
171
+ suffix = '.'+partstr;
160
172
  }
161
173
 
162
174
  if (index['*'+suffix]) { // *.domain exists (e.g. *.kyoto.jp for domain='kyoto.jp');
163
175
  return null;
164
176
  }
165
177
 
166
- if (suffixLen && parts.length > suffixLen) {
167
- 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;
168
182
  }
169
183
 
170
184
  return null;
@@ -175,7 +189,7 @@ function checkPublicSuffix(give,get) {
175
189
  assert.equal(got, get, give+' should be '+(get==null?'NULL':get)+' but got '+got);
176
190
  }
177
191
 
178
- // 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
179
193
  function pubSufTest() {
180
194
  // For this function-scope and this function-scope ONLY:
181
195
  // Any copyright is dedicated to the Public Domain.
@@ -194,14 +208,14 @@ function pubSufTest() {
194
208
  checkPublicSuffix('.example.example', null);
195
209
  // Unlisted TLD.
196
210
  checkPublicSuffix('example', null);
197
- checkPublicSuffix('example.example', null);
198
- checkPublicSuffix('b.example.example', null);
199
- 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');
200
214
  // Listed, but non-Internet, TLD.
201
- checkPublicSuffix('local', null);
202
- checkPublicSuffix('example.local', null);
203
- checkPublicSuffix('b.example.local', null);
204
- 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);
205
219
  // TLD with only 1 rule.
206
220
  checkPublicSuffix('biz', null);
207
221
  checkPublicSuffix('domain.biz', 'domain.biz');
@@ -230,20 +244,22 @@ function pubSufTest() {
230
244
  checkPublicSuffix('test.ac.jp', 'test.ac.jp');
231
245
  checkPublicSuffix('www.test.ac.jp', 'test.ac.jp');
232
246
  checkPublicSuffix('kyoto.jp', null);
233
- checkPublicSuffix('c.kyoto.jp', null);
234
- checkPublicSuffix('b.c.kyoto.jp', 'b.c.kyoto.jp');
235
- checkPublicSuffix('a.b.c.kyoto.jp', 'b.c.kyoto.jp');
236
- checkPublicSuffix('pref.kyoto.jp', 'pref.kyoto.jp'); // Exception rule.
237
- checkPublicSuffix('www.pref.kyoto.jp', 'pref.kyoto.jp'); // Exception rule.
238
- checkPublicSuffix('city.kyoto.jp', 'city.kyoto.jp'); // Exception rule.
239
- 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');
240
256
  // TLD with a wildcard rule and exceptions.
241
- checkPublicSuffix('om', null);
242
- checkPublicSuffix('test.om', null);
243
- checkPublicSuffix('b.test.om', 'b.test.om');
244
- checkPublicSuffix('a.b.test.om', 'b.test.om');
245
- checkPublicSuffix('songfest.om', 'songfest.om');
246
- 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');
247
263
  // US K12.
248
264
  checkPublicSuffix('us', null);
249
265
  checkPublicSuffix('test.us', 'test.us');
@@ -254,6 +270,24 @@ function pubSufTest() {
254
270
  checkPublicSuffix('k12.ak.us', null);
255
271
  checkPublicSuffix('test.k12.ak.us', 'test.k12.ak.us');
256
272
  checkPublicSuffix('www.test.k12.ak.us', 'test.k12.ak.us');
257
-
258
-
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);
259
293
  }