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

getHostname with enabled validateHostname and parse().hostname return different results #2258

Open
105th opened this issue Jan 23, 2025 · 0 comments

Comments

@105th
Copy link

105th commented Jan 23, 2025

Description:

I have encountered an issue where getHostname(url) and parse(url).hostname return different results for the same URL. This inconsistency can lead to unexpected behavior in applications relying on these functions. I suppose this happens, because if only getHostname has been used (https://github.com/remusao/tldts/blob/master/packages/tldts-core/src/factory.ts#L112), it will not apply extra validation (https://github.com/remusao/tldts/blob/master/packages/tldts-core/src/factory.ts#L126) regardless to passed options.

Steps to Reproduce:

Use the following URL: ___id___.c.mystat-in.net
Call getHostname(url) and parse(url).hostname with the URL.

Example Code:

const tldts = require('tldts');

const url = '___id___.c.mystat-in.net';

const hostname1 = tldts.getHostname(url);
const hostname2 = tldts.getHostname(url, { validateHostname: true });
const hostname3 = tldts.parse(url).hostname;

console.log(`getHostname: ${hostname1}`); // Output: ___id___.c.mystat-in.net
console.log(`getHostname with validation: ${hostname2}`); // Output: ___id___.c.mystat-in.net
console.log(`parse.hostname: ${hostname3}`); // Output: null

Expected Behavior:

Both getHostname(url) and parse(url).hostname should return the same hostname.

Actual Behavior:

getHostname(url) returns: id.c.mystat-in.net
parse(url).hostname returns: null

Environment:

tldts version: 6.1.74
Node.js version: v18.19.1
Operating System: MacOS 12.5

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

1 participant