diff --git a/src/gui/IconDownloader.cpp b/src/gui/IconDownloader.cpp index 42b1b09af..d1e8c7c24 100644 --- a/src/gui/IconDownloader.cpp +++ b/src/gui/IconDownloader.cpp @@ -21,7 +21,6 @@ #include "networking/NetworkManager.h" #include -#include #include #include @@ -72,14 +71,9 @@ void IconDownloader::setUrl(const QString& entryUrl) QString fullyQualifiedDomain = url.host(); - // Determine if host portion of URL is an IP address by resolving it and - // searching for a match with the returned address(es). - bool hostIsIp = false; - QList hostAddresses = QHostInfo::fromName(fullyQualifiedDomain).addresses(); - hostIsIp = - std::any_of(hostAddresses.begin(), hostAddresses.end(), [&fullyQualifiedDomain](const QHostAddress& addr) { - return addr.toString() == fullyQualifiedDomain; - }); + // Determine if host portion of URL is an IP address. This must not resolve the + // host name, as a blocking DNS lookup would freeze the UI. + const bool hostIsIp = UrlTools::isIpAddress(fullyQualifiedDomain); // Determine the second-level domain, if available QString secondLevelDomain; diff --git a/tests/TestIconDownloader.cpp b/tests/TestIconDownloader.cpp index 44aebd74c..d912834a4 100644 --- a/tests/TestIconDownloader.cpp +++ b/tests/TestIconDownloader.cpp @@ -97,6 +97,10 @@ void TestIconDownloader::testIconDownloader_data() << QStringList{"https://user:password@de.login.keepassxc.org/favicon.ico", "https://user:password@keepassxc.org/favicon.ico", "https://keepassxc.org/favicon.ico"}; + QTest::newRow("Raw IPv6 with schema") + << "https://[2001:db8::1]" << QStringList{"https://[2001:db8::1]/favicon.ico"}; + QTest::newRow("Raw IPv6 with schema and port") + << "https://[2001:db8::1]:8080" << QStringList{"https://[2001:db8::1]:8080/favicon.ico"}; QTest::newRow("Raw IP with username and password") << "https://user:password@134.130.155.184" << QStringList{"https://user:password@134.130.155.184/favicon.ico"}; QTest::newRow("Relative path should be preserved")