lupomontero / psl

JavaScript domain name parser based on the Public Suffix List
https://www.npmjs.org/package/psl
MIT License
388 stars 80 forks source link

domain is not parsed correctly for `run.app` #308

Open RezaRahmati opened 1 year ago

RezaRahmati commented 1 year ago

Steps to reproduce:

const parsed = psl.parse('health-check-tool-2-api-izeboapi4q-nn.a.run.app')
console.log(parsed.domain)

expected: run.app

actual: health-check-tool-2-api-izeboapi4q-nn.a.run.app

version: "psl": "^1.9.0",

p.s app.run is the default google cloud run domain

from examples on readme

// Parse domain with nested subdomains
var parsed = psl.parse('a.b.c.d.foo.com');
console.log(parsed.tld); // 'com'
console.log(parsed.sld); // 'foo'
console.log(parsed.domain); // 'foo.com'
console.log(parsed.subdomain); // 'a.b.c.d'

Also added a request https://github.com/publicsuffix/list/issues/1710

bobmorley commented 1 year ago

I do not think this is an issue. As per https://github.com/publicsuffix/list/issues/1710 run.app is already on the list.

Moreover, a.run.app is also a TLD on the list; so the actual result here is correct.

agustingianni commented 9 months ago

I think I'm having a similar issue:

console.log(psl.parse('s3.eu-central-1.amazonaws.com'))

Gives me:

input: "s3.eu-central-1.amazonaws.com"
tld: "s3.eu-central-1.amazonaws.com"
sld: null
domain: null
subdomain: null
listed: true
BlackWolfWoof commented 7 months ago

I am having the same issue with altervista.org which is also on the list. Why? It isn't even a TLD

Lil fix on my end to deal with this😹

import psl from 'psl';
const url = "https://altervista.org"

let domain = new URL(url).host
let domainParse = psl.parse(domain);
let rootDomain = domainParse.domain || domainParse.tld

console.log('domain: ' + domain)
console.log(domainParse)
console.log('rootDomain: ' + rootDomain)

image

lupomontero commented 5 days ago

Hi @RezaRahmati, @agustingianni and @BlackWolfWoof :wave: Many apologies for the delay in getting back to you.

Please note that psl is not a standard domain name parser, but rather a tool to check against the Public Suffix List. The parsed object property names can be confusing as in the context of the public suffix list, the tld here would actually mean the publicSuffix. So this is the expected behaviour. Now that *.run.app is in the official list, the result is as follows:

psl.parse('health-check-tool-2-api-izeboapi4q-nn.a.run.app')

Return value:

{
  input: 'health-check-tool-2-api-izeboapi4q-nn.a.run.app',
  tld: 'a.run.app',
  sld: 'health-check-tool-2-api-izeboapi4q-nn',
  domain: 'health-check-tool-2-api-izeboapi4q-nn.a.run.app',
  subdomain: null,
  listed: true
}

I'm actually considering adding new props or renaming existing ones in the parsed object to avoid this confusion (happens often). Thanks for all the feedback.