mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 14:04:23 +00:00
Use hostname instead of domain name in tracker filter list
Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com> PR #19062. Closes #19035.
This commit is contained in:
parent
a5e8af5070
commit
2e87e6e0df
@ -62,18 +62,14 @@ namespace
|
|||||||
|
|
||||||
QString getHost(const QString &url)
|
QString getHost(const QString &url)
|
||||||
{
|
{
|
||||||
// We want the domain + tld. Subdomains should be disregarded
|
// We want the hostname.
|
||||||
// If failed to parse the domain or IP address, original input should be returned
|
// If failed to parse the domain, original input should be returned
|
||||||
|
|
||||||
const QString host = QUrl(url).host();
|
const QString host = QUrl(url).host();
|
||||||
if (host.isEmpty())
|
if (host.isEmpty())
|
||||||
return url;
|
return url;
|
||||||
|
|
||||||
// host is in IP format
|
return host;
|
||||||
if (!QHostAddress(host).isNull())
|
|
||||||
return host;
|
|
||||||
|
|
||||||
return host.section(u'.', -2, -1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString NULL_HOST = u""_qs;
|
const QString NULL_HOST = u""_qs;
|
||||||
|
@ -95,28 +95,18 @@ const getShowFiltersSidebar = function() {
|
|||||||
return (show === null) || (show === 'true');
|
return (show === null) || (show === 'true');
|
||||||
};
|
};
|
||||||
|
|
||||||
const isValidIpAddress = (() => {
|
|
||||||
const v4 = '^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\/([0-9]|[1-2][0-9]|3[0-2]))?$';
|
|
||||||
const v6segment = '[0-9A-Fa-f]{1,4}';
|
|
||||||
const v6 = `^\\s*(((${v6segment}:){7}(${v6segment}|:))|((${v6segment}:){6}(:${v6segment}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|((${v6segment}:){5}(((:${v6segment}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|((${v6segment}:){4}(((:${v6segment}){1,3})|((:${v6segment})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|((${v6segment}:){3}(((:${v6segment}){1,4})|((:${v6segment}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|((${v6segment}:){2}(((:${v6segment}){1,5})|((:${v6segment}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|((${v6segment}:){1}(((:${v6segment}){1,6})|((:${v6segment}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:${v6segment}){1,7})|((:${v6segment}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?\\s*(\\/(\\d|\\d\\d|1[0-1]\\d|12[0-8]))?$`;
|
|
||||||
const ipRegex = new RegExp(`(?:^${v4}$)|(?:^${v6}$)`);
|
|
||||||
|
|
||||||
return (ip) => ipRegex.test(ip);
|
|
||||||
})();
|
|
||||||
|
|
||||||
// getHost emulate the GUI version `QString getHost(const QString &url)`
|
// getHost emulate the GUI version `QString getHost(const QString &url)`
|
||||||
function getHost(url) {
|
function getHost(url) {
|
||||||
// We want the domain + tld. Subdomains should be disregarded
|
// We want the hostname.
|
||||||
// If failed to parse the domain or IP address, original input should be returned
|
// If failed to parse the domain, original input should be returned
|
||||||
|
|
||||||
const scheme = url.slice(0, 6).toLowerCase();
|
if (!/^(?:https?|udp):/i.test(url)) {
|
||||||
if (!(scheme.startsWith('http:') || scheme.startsWith('https:') || scheme.startsWith('udp:'))) {
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// hack: URL can not get hostname from udp protocol
|
// hack: URL can not get hostname from udp protocol
|
||||||
const parsedUrl = new URL(url.replace(/^udp:/, 'https:'));
|
const parsedUrl = new URL(url.replace(/^udp:/i, 'https:'));
|
||||||
// host: "example.com:8443"
|
// host: "example.com:8443"
|
||||||
// hostname: "example.com"
|
// hostname: "example.com"
|
||||||
const host = parsedUrl.hostname;
|
const host = parsedUrl.hostname;
|
||||||
@ -124,13 +114,7 @@ function getHost(url) {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// host is in IP format
|
return host;
|
||||||
if (isValidIpAddress(host)) {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: support TLDs like .co.uk
|
|
||||||
return host.split(/\./).slice(-2).join('.');
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
return url;
|
return url;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user