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.
- package/README.md +189 -127
- package/generate-pubsuffix.js +60 -26
- package/lib/cookie.js +330 -171
- package/lib/memstore.js +33 -6
- package/lib/pathMatch.js +61 -0
- package/lib/permuteDomain.js +56 -0
- package/lib/pubsuffix.js +25 -6
- package/lib/store.js +5 -1
- package/package.json +5 -8
- package/public-suffix.txt +5752 -672
- package/test/api_test.js +0 -16
- package/test/cookie_sorting_test.js +66 -0
- package/test/cookie_to_json_test.js +2 -2
- package/test/domain_and_path_test.js +2 -2
- package/test/ietf_test.js +1 -2
- package/test/jar_serialization_test.js +348 -0
- package/test/parsing_test.js +71 -133
- package/test/regression_test.js +15 -0
- package/tough-cookie-deps.tsv +0 -6
package/generate-pubsuffix.js
CHANGED
|
@@ -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 = '.'+
|
|
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
|
-
|
|
167
|
-
|
|
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://
|
|
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',
|
|
198
|
-
checkPublicSuffix('b.example.example',
|
|
199
|
-
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');
|
|
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('
|
|
234
|
-
checkPublicSuffix('
|
|
235
|
-
checkPublicSuffix('
|
|
236
|
-
checkPublicSuffix('
|
|
237
|
-
checkPublicSuffix('
|
|
238
|
-
checkPublicSuffix('
|
|
239
|
-
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');
|
|
240
256
|
// TLD with a wildcard rule and exceptions.
|
|
241
|
-
checkPublicSuffix('
|
|
242
|
-
checkPublicSuffix('test.
|
|
243
|
-
checkPublicSuffix('b.test.
|
|
244
|
-
checkPublicSuffix('a.b.test.
|
|
245
|
-
checkPublicSuffix('
|
|
246
|
-
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');
|
|
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
|
}
|