Improve domain matching to reduce false positives (#172)

This commit is contained in:
Maxim Baz
2019-09-26 23:22:20 +02:00
committed by GitHub
parent dce3358d7f
commit 14302e9362

View File

@@ -31,11 +31,15 @@ function pathToDomain(path, currentHost) {
continue;
}
var t = TldJS.parse(parts[key]);
// Part is considered to be a domain component in one of the following cases:
// - it is a valid domain with well-known TLD (github.com, login.github.com)
// - it is a valid domain with unknown TLD but the current host is it's subdomain (login.pi.hole)
// - it is or isnt a valid domain but the current host matches it EXACTLY (localhost, pi.hole)
if (
t.isValid &&
((t.tldExists && t.domain !== null) ||
t.hostname === currentHost ||
currentHost.endsWith(`.${t.hostname}`))
((t.domain !== null && (t.tldExists || currentHost.endsWith(`.${t.hostname}`))) ||
currentHost === t.hostname)
) {
return t.hostname;
}