diff --git a/lib/cookie/cookie.ts b/lib/cookie/cookie.ts index c3dd7da2..3929ec58 100644 --- a/lib/cookie/cookie.ts +++ b/lib/cookie/cookie.ts @@ -32,7 +32,7 @@ // This file was too big before we added max-lines, and it's ongoing work to reduce its size. /* eslint max-lines: [1, 750] */ -import * as pubsuffix from '../pubsuffix-psl' +import { getPublicSuffix } from '../getPublicSuffix' import * as validators from '../validators' import { getCustomInspectSymbol } from '../utilHelper' import { inOperator } from '../utils' @@ -559,7 +559,7 @@ export class Cookie { if (cdomain.match(/\.$/)) { return false // S4.1.2.3 suggests that this is bad. domainMatch() tests confirm this } - const suffix = pubsuffix.getPublicSuffix(cdomain) + const suffix = getPublicSuffix(cdomain) if (suffix == null) { // it's a public suffix return false diff --git a/lib/cookie/cookieJar.ts b/lib/cookie/cookieJar.ts index 32cdd9b7..6b60e099 100644 --- a/lib/cookie/cookieJar.ts +++ b/lib/cookie/cookieJar.ts @@ -1,6 +1,6 @@ import urlParse from 'url-parse' -import * as pubsuffix from '../pubsuffix-psl' +import { getPublicSuffix } from '../getPublicSuffix' import * as validators from '../validators' import { Store } from '../store' import { MemoryCookieStore } from '../memstore' @@ -303,7 +303,7 @@ export class CookieJar { const cdomain = cookie.cdomain() const suffix = typeof cdomain === 'string' - ? pubsuffix.getPublicSuffix(cdomain, { + ? getPublicSuffix(cdomain, { allowSpecialUseDomain: this.allowSpecialUseDomain, ignoreError: options?.ignoreError, }) diff --git a/lib/cookie/index.ts b/lib/cookie/index.ts index 1b167c28..f15b6f62 100644 --- a/lib/cookie/index.ts +++ b/lib/cookie/index.ts @@ -1,7 +1,7 @@ export { MemoryCookieStore } from '../memstore' export { pathMatch } from '../pathMatch' export { permuteDomain } from '../permuteDomain' -export { getPublicSuffix } from '../pubsuffix-psl' +export { getPublicSuffix } from '../getPublicSuffix' export { Store } from '../store' export { ParameterError } from '../validators' export { version } from '../version' @@ -18,4 +18,5 @@ export { parseDate } from './parseDate' export { permutePath } from './permutePath' import { Cookie } from './cookie' + export const fromJSON = Cookie.fromJSON diff --git a/lib/pubsuffix-psl.ts b/lib/getPublicSuffix.ts similarity index 96% rename from lib/pubsuffix-psl.ts rename to lib/getPublicSuffix.ts index a1cc5209..7e7967cf 100644 --- a/lib/pubsuffix-psl.ts +++ b/lib/getPublicSuffix.ts @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ 'use strict' -import * as psl from 'psl' +import { getDomain } from 'tldts' // RFC 6761 const SPECIAL_USE_DOMAINS = ['local', 'example', 'invalid', 'localhost', 'test'] @@ -84,5 +84,8 @@ export function getPublicSuffix( ) } - return psl.get(domain) + return getDomain(domain, { + allowIcannDomains: true, + allowPrivateDomains: true, + }) } diff --git a/lib/permuteDomain.ts b/lib/permuteDomain.ts index 0809a5df..195d7267 100644 --- a/lib/permuteDomain.ts +++ b/lib/permuteDomain.ts @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ 'use strict' -import { getPublicSuffix } from './pubsuffix-psl' +import { getPublicSuffix } from './getPublicSuffix' // Gives the permutation of all possible domainMatch()es of a given domain. The // array is in shortest-to-longest order. Handy for indexing. diff --git a/package-lock.json b/package-lock.json index 52f53349..0fc625fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "5.0.0-rc.0", "license": "BSD-3-Clause", "dependencies": { - "psl": "^1.9.0", "punycode": "^2.3.1", + "tldts": "^6.1.0", "url-parse": "^1.5.10" }, "devDependencies": { @@ -6082,11 +6082,6 @@ "node": ">= 6" } }, - "node_modules/psl": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", - "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -6483,6 +6478,22 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, + "node_modules/tldts": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.2.tgz", + "integrity": "sha512-bmIVB9OKvYlNcEoCRpa2swYlLpAmhLvGlXMZ0pSzmbU+0S/LNZJwTzHB56Fom7m9XCVh+mf2RDyCTRgX6MRDjQ==", + "dependencies": { + "tldts-core": "^6.1.2" + }, + "bin": { + "tldts": "bin/cli.js" + } + }, + "node_modules/tldts-core": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.2.tgz", + "integrity": "sha512-cFBCCSilkRe/7JkZrQlzqhWDE0r1irpEYRp5XiFLFGl8fTwN4eWqutyx9wfFaDfmVv7E7pQMUZnM1VHnOid5Vw==" + }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", @@ -11374,11 +11385,6 @@ "sisteransi": "^1.0.5" } }, - "psl": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", - "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==" - }, "punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -11650,6 +11656,19 @@ "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, + "tldts": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.2.tgz", + "integrity": "sha512-bmIVB9OKvYlNcEoCRpa2swYlLpAmhLvGlXMZ0pSzmbU+0S/LNZJwTzHB56Fom7m9XCVh+mf2RDyCTRgX6MRDjQ==", + "requires": { + "tldts-core": "^6.1.2" + } + }, + "tldts-core": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.2.tgz", + "integrity": "sha512-cFBCCSilkRe/7JkZrQlzqhWDE0r1irpEYRp5XiFLFGl8fTwN4eWqutyx9wfFaDfmVv7E7pQMUZnM1VHnOid5Vw==" + }, "tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", diff --git a/package.json b/package.json index b84d874b..74be9da4 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "vows": "^0.8.3" }, "dependencies": { - "psl": "^1.9.0", + "tldts": "^6.1.0", "punycode": "^2.3.1", "url-parse": "^1.5.10" }