1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

LocationBar: Only allow spaces in url query

Fixes correctly searching for "site:website.com searchterm"

BUG: 389491
This commit is contained in:
David Rosca 2018-01-27 10:40:36 +01:00
parent 2e7436c741
commit 958fc63f01
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
3 changed files with 29 additions and 3 deletions

View File

@ -128,6 +128,28 @@ void LocationBarTest::loadActionSearchTest()
QCOMPARE(action.loadRequest.url(), QUrl("http://test/ttt-notsearch"));
}
void LocationBarTest::loadAction_kdebug389491()
{
// "site:website.com searchterm" is loaded instead of searched
SearchEngine engine;
engine.name = "Test Engine";
engine.url = "http://test/%s";
engine.shortcut = "t";
mApp->searchEnginesManager()->addEngine(engine);
mApp->searchEnginesManager()->setActiveEngine(engine);
LocationBar::LoadAction action;
action = LocationBar::loadAction("site:website.com searchterm");
QCOMPARE(action.type, LocationBar::LoadAction::Search);
QCOMPARE(action.loadRequest.url(), QUrl("http://test/site%3Awebsite.com%20searchterm"));
action = LocationBar::loadAction("site:website.com?search=searchterm and another");
QCOMPARE(action.type, LocationBar::LoadAction::Url);
QCOMPARE(action.loadRequest.url(), QUrl("site:website.com?search=searchterm and another"));
}
int main(int argc, char **argv)
{
MainApplication::setTestModeEnabled(true);

View File

@ -31,4 +31,5 @@ private slots:
void loadActionBasicTest();
void loadActionBookmarksTest();
void loadActionSearchTest();
void loadAction_kdebug389491();
};

View File

@ -263,9 +263,12 @@ LocationBar::LoadAction LocationBar::loadAction(const QString &text)
// Otherwise load as url
const QUrl &guessedUrl = QUrl::fromUserInput(t);
if (guessedUrl.isValid()) {
action.type = LoadAction::Url;
action.loadRequest = guessedUrl;
return action;
// We only allow space in query
if (!QzTools::containsSpace(guessedUrl.toString(QUrl::RemoveQuery))) {
action.type = LoadAction::Url;
action.loadRequest = guessedUrl;
return action;
}
}
// Search when creating url failed