Wrong top level domain detection based on the public suffix list
mehrdadep opened this issue · 1 comments
mehrdadep commented
Issue summary
As you can see here the eu.org
belongs to the private domain section, so parsing a domain like example.eu.org
should return org
as the top-level domain, not the eu.org
(I've mistaken these two concepts as well and opened a similar issue for a php package.)
Information | Description |
---|---|
Module version | 7.0.1 |
Node version | 16.17.0 |
OS Platform | Linux 5.19.0-76051900-generic |
Standalone code, or another way to reproduce the problem
import { parseDomain, ParseResultType } from "parse-domain";
const parseResult = parseDomain(
// This should be a string with basic latin letters only.
// More information below.
"example.eu.org"
);
// Check if the domain is listed in the public suffix list
if (parseResult.type === ParseResultType.Listed) {
const { subDomains, domain, topLevelDomains } = parseResult;
console.log(subDomains); // []
console.log(domain); // "example"
console.log(topLevelDomains); // ["eu", "org"]
} else {
// Read more about other parseResult types below...
}
Expected result
org
Actual result
eu.org
jhnns commented
We include private top-level domains by default as mentioned here. This is because browsers do this as well (when calculating the scope of a cookie for instance).
You can use the parseResult.icann
property if you only care about ICANN domains:
const parseResult = parseDomain(
"example.eu.org"
);
const { subDomains, domain, topLevelDomains } = parseResult.icann;
console.log(subDomains); // ["example"]
console.log(domain); // "eu"
console.log(topLevelDomains); // ["org"]