1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

LocationBar: Fix transforming text to url when searching is disabled

Closes #2578
This commit is contained in:
David Rosca 2018-01-29 09:42:24 +01:00
parent efe806e65e
commit 1c4937b64c
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
3 changed files with 39 additions and 2 deletions

View File

@ -21,6 +21,7 @@
#include "searchenginesmanager.h" #include "searchenginesmanager.h"
#include "bookmarks.h" #include "bookmarks.h"
#include "bookmarkitem.h" #include "bookmarkitem.h"
#include "qzsettings.h"
static void removeBookmarks(BookmarkItem *parent) static void removeBookmarks(BookmarkItem *parent)
{ {
@ -173,4 +174,36 @@ void LocationBarTest::loadActionSpecialSchemesTest()
QCOMPARE(action.loadRequest.url(), QUrl("about:blank")); 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) FALKONTEST_MAIN(LocationBarTest)

View File

@ -33,4 +33,5 @@ private slots:
void loadActionSearchTest(); void loadActionSearchTest();
void loadAction_kdebug389491(); void loadAction_kdebug389491();
void loadActionSpecialSchemesTest(); void loadActionSpecialSchemesTest();
void loadAction_issue2578();
}; };

View File

@ -243,8 +243,11 @@ LocationBar::LoadAction LocationBar::loadAction(const QString &text)
} }
if (!qzSettings->searchFromAddressBar) { if (!qzSettings->searchFromAddressBar) {
const QUrl &guessedUrl = QUrl::fromUserInput(t);
if (guessedUrl.isValid()) {
action.type = LoadAction::Url; action.type = LoadAction::Url;
action.loadRequest = QUrl(t); action.loadRequest = guessedUrl;
}
return action; return action;
} }