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

Wrong top level domain detection based on the public suffix list #147

Closed
mehrdadep opened this issue Sep 7, 2022 · 1 comment
Closed

Comments

@mehrdadep
Copy link

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
@mehrdadep mehrdadep changed the title Wrong top level domain detection based on public suffix list Wrong top level domain detection based on the public suffix list Sep 7, 2022
@jhnns
Copy link
Member

jhnns commented Oct 27, 2023

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"]

@jhnns jhnns closed this as completed Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants