diff --git a/autotests/locationbartest.cpp b/autotests/locationbartest.cpp index dc38e7ee3..25ad204b0 100644 --- a/autotests/locationbartest.cpp +++ b/autotests/locationbartest.cpp @@ -21,6 +21,7 @@ #include "searchenginesmanager.h" #include "bookmarks.h" #include "bookmarkitem.h" +#include "qzsettings.h" static void removeBookmarks(BookmarkItem *parent) { @@ -173,4 +174,36 @@ void LocationBarTest::loadActionSpecialSchemesTest() 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); +} + FALKONTEST_MAIN(LocationBarTest) diff --git a/autotests/locationbartest.h b/autotests/locationbartest.h index 3b27e35e2..441eff839 100644 --- a/autotests/locationbartest.h +++ b/autotests/locationbartest.h @@ -33,4 +33,5 @@ private slots: void loadActionSearchTest(); void loadAction_kdebug389491(); void loadActionSpecialSchemesTest(); + void loadAction_issue2578(); }; diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index d02361057..874f610ab 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; }