From 310d447aa0aef85bcd24eb6973eef324f0746cf0 Mon Sep 17 00:00:00 2001 From: Felix Berlakovich Date: Wed, 11 Feb 2026 16:57:16 +0100 Subject: [PATCH] Reuse existing URLTools functionality where possible --- src/autofill/AutoFillUtils.h | 22 +++++++++++++++------- tests/CMakeLists.txt | 3 +-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/autofill/AutoFillUtils.h b/src/autofill/AutoFillUtils.h index 792561261..140c1a9c0 100644 --- a/src/autofill/AutoFillUtils.h +++ b/src/autofill/AutoFillUtils.h @@ -18,8 +18,10 @@ #ifndef KEEPASSX_AUTOFILL_UTILS_H #define KEEPASSX_AUTOFILL_UTILS_H -#include +#include "gui/UrlTools.h" + #include +#include #include namespace AutoFillUtils @@ -74,13 +76,19 @@ inline bool hostsMatch(const QString& requested, const QString& candidate) return true; } - // Only allow subdomain matching when the shorter side has at least one dot - // (i.e. is a real domain, not a bare TLD like "com") - if (requested.endsWith('.' + candidate)) { - return candidate.contains('.'); + // IP addresses require exact match only (already handled above) + if (urlTools()->isIpAddress(requested) || urlTools()->isIpAddress(candidate)) { + return false; } - if (candidate.endsWith('.' + requested)) { - return requested.contains('.'); + + // Base domains must match (follows BrowserService::handleURL pattern) + if (urlTools()->getBaseDomainFromUrl(requested) != urlTools()->getBaseDomainFromUrl(candidate)) { + return false; + } + + // Allow subdomain matching when one host ends with the other + if (requested.endsWith('.' + candidate) || candidate.endsWith('.' + requested)) { + return true; } return false; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a77c07439..2dde799b2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -240,10 +240,9 @@ endif() if(WITH_XC_NETWORKING OR WITH_XC_BROWSER) add_unit_test(NAME testurltools SOURCES TestUrlTools.cpp LIBS ${TEST_LIBRARIES}) + add_unit_test(NAME testautofillutils SOURCES TestAutoFillUtils.cpp LIBS ${TEST_LIBRARIES}) endif() -add_unit_test(NAME testautofillutils SOURCES TestAutoFillUtils.cpp LIBS ${TEST_LIBRARIES}) - add_unit_test(NAME testcli SOURCES TestCli.cpp LIBS testsupport cli ${ZXCVBN_LIBRARIES} ${TEST_LIBRARIES}) target_compile_definitions(testcli PRIVATE KEEPASSX_CLI_PATH="$")