Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace psl with tldts #346

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/cookie/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/cookie/cookieJar.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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,
})
Expand Down
3 changes: 2 additions & 1 deletion lib/cookie/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -18,4 +18,5 @@ export { parseDate } from './parseDate'
export { permutePath } from './permutePath'

import { Cookie } from './cookie'

export const fromJSON = Cookie.fromJSON
7 changes: 5 additions & 2 deletions lib/pubsuffix-psl.ts → lib/getPublicSuffix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -84,5 +84,8 @@ export function getPublicSuffix(
)
}

return psl.get(domain)
return getDomain(domain, {
allowIcannDomains: true,
allowPrivateDomains: true,
})
}
2 changes: 1 addition & 1 deletion lib/permuteDomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Loading