From 9aec84dee713027ceb4ffd58ed5d0b8d81484e7e Mon Sep 17 00:00:00 2001 From: m5w6 <35432036+m5w6@users.noreply.github.com> Date: Sat, 4 Sep 2021 23:41:37 +0200 Subject: [PATCH] Add "parent directory match" priority between exact and host match --- src/browser/BrowserService.cpp | 5 +++++ tests/TestBrowser.cpp | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/browser/BrowserService.cpp b/src/browser/BrowserService.cpp index 3150fa873..988bf0184 100644 --- a/src/browser/BrowserService.cpp +++ b/src/browser/BrowserService.cpp @@ -948,6 +948,11 @@ int BrowserService::sortPriority(const QStringList& urls, const QString& siteUrl return 90; } + // Parent directory match + if (url.isParentOf(siteUrl) || url.isParentOf(formUrl)) { + return 85; + } + // Match without path (ie, FQDN match), form url prioritizes lower than site url if (url.host() == siteUrl.host()) { return 80; diff --git a/tests/TestBrowser.cpp b/tests/TestBrowser.cpp index d21fbcffa..8229ac259 100644 --- a/tests/TestBrowser.cpp +++ b/tests/TestBrowser.cpp @@ -165,10 +165,13 @@ void TestBrowser::testSortPriority_data() QTest::newRow("Site Query Mismatch") << siteUrl << siteUrl + "?test=test" << formUrl << 90; - QTest::newRow("Path Mismatch (site)") << "https://github.com/" << siteUrl << formUrl << 80; - QTest::newRow("Path Mismatch (site) No Scheme") << "github.com" << siteUrl << formUrl << 80; + QTest::newRow("Path Mismatch (site)") << "https://github.com/" << siteUrl << formUrl << 85; + QTest::newRow("Path Mismatch (site) No Scheme") << "github.com" << siteUrl << formUrl << 85; QTest::newRow("Path Mismatch (form)") << "https://github.com/" - << "https://github.net" << formUrl << 70; + << "https://github.net" << formUrl << 85; + QTest::newRow("Path Mismatch (diff parent)") << "https://github.com/keepassxreboot" << siteUrl << formUrl << 80; + QTest::newRow("Path Mismatch (diff parent, form)") << "https://github.com/keepassxreboot" + << "https://github.net" << formUrl << 70; QTest::newRow("Subdomain Mismatch (site)") << siteUrl << "https://sub.github.com/" << "https://github.net/" << 60;