Skip to content

Commit 14302e9

Browse files
authored
Improve domain matching to reduce false positives (#172)
1 parent dce3358 commit 14302e9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/helpers.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ function pathToDomain(path, currentHost) {
3131
continue;
3232
}
3333
var t = TldJS.parse(parts[key]);
34+
35+
// Part is considered to be a domain component in one of the following cases:
36+
// - it is a valid domain with well-known TLD (github.com, login.github.com)
37+
// - it is a valid domain with unknown TLD but the current host is it's subdomain (login.pi.hole)
38+
// - it is or isnt a valid domain but the current host matches it EXACTLY (localhost, pi.hole)
3439
if (
3540
t.isValid &&
36-
((t.tldExists && t.domain !== null) ||
37-
t.hostname === currentHost ||
38-
currentHost.endsWith(`.${t.hostname}`))
41+
((t.domain !== null && (t.tldExists || currentHost.endsWith(`.${t.hostname}`))) ||
42+
currentHost === t.hostname)
3943
) {
4044
return t.hostname;
4145
}

0 commit comments

Comments
 (0)