From f3b770d22c3c2309760aedbbf9b7c9f75e653d96 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Mon, 29 Jan 2018 09:42:24 +0100 Subject: [PATCH] LocationBar: Fix transforming text to url when searching is disabled Closes #2578 --- src/lib/navigation/locationbar.cpp | 7 ++++-- tests/autotests/locationbartest.cpp | 33 +++++++++++++++++++++++++++++ tests/autotests/locationbartest.h | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 6d1117e86..c3cf31bf1 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -243,8 +243,11 @@ LocationBar::LoadAction LocationBar::loadAction(const QString &text) } if (!qzSettings->searchFromAddressBar) { - action.type = LoadAction::Url; - action.loadRequest = QUrl(t); + const QUrl &guessedUrl = QUrl::fromUserInput(t); + if (guessedUrl.isValid()) { + action.type = LoadAction::Url; + action.loadRequest = guessedUrl; + } return action; } diff --git a/tests/autotests/locationbartest.cpp b/tests/autotests/locationbartest.cpp index 1984c21fc..8c93386eb 100644 --- a/tests/autotests/locationbartest.cpp +++ b/tests/autotests/locationbartest.cpp @@ -21,6 +21,7 @@ #include "searchenginesmanager.h" #include "bookmarks.h" #include "bookmarkitem.h" +#include "qzsettings.h" #include @@ -174,3 +175,35 @@ void LocationBarTest::loadActionSpecialSchemesTest() QCOMPARE(action.type, LocationBar::LoadAction::Url); QCOMPARE(action.loadRequest.url(), QUrl("about:blank")); } + +void LocationBarTest::loadAction_issue2578() +{ + // typed text is not correctly transformed to QUrl when searchFromAddressBar is disabled + + qzSettings->searchFromAddressBar = false; + + LocationBar::LoadAction action; + + action = LocationBar::loadAction("github.com"); + QCOMPARE(action.type, LocationBar::LoadAction::Url); + QCOMPARE(action.loadRequest.url(), QUrl("http://github.com")); + + action = LocationBar::loadAction("github"); + QCOMPARE(action.type, LocationBar::LoadAction::Url); + QCOMPARE(action.loadRequest.url(), QUrl("http://github")); + + action = LocationBar::loadAction("github/test/path"); + QCOMPARE(action.type, LocationBar::LoadAction::Url); + QCOMPARE(action.loadRequest.url(), QUrl("http://github/test/path")); + + action = LocationBar::loadAction("localhost"); + QCOMPARE(action.type, LocationBar::LoadAction::Url); + QCOMPARE(action.loadRequest.url(), QUrl("http://localhost")); + + action = LocationBar::loadAction("localhost/test/path"); + QCOMPARE(action.type, LocationBar::LoadAction::Url); + QCOMPARE(action.loadRequest.url(), QUrl("http://localhost/test/path")); + + action = LocationBar::loadAction("github.com foo bar"); + QCOMPARE(action.type, LocationBar::LoadAction::Invalid); +} diff --git a/tests/autotests/locationbartest.h b/tests/autotests/locationbartest.h index d93162ecf..dc26507c5 100644 --- a/tests/autotests/locationbartest.h +++ b/tests/autotests/locationbartest.h @@ -33,4 +33,5 @@ private slots: void loadActionSearchTest(); void loadAction_kdebug389491(); void loadActionSpecialSchemesTest(); + void loadAction_issue2578(); };