From 736218793abd50d04bf140cc5cd2a8e9292c47f3 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sun, 13 Dec 2020 09:43:08 +0100 Subject: [PATCH] Expand ENV variables before displaying results Before the variables would get expanded later and consequently go through another code path than file locations. This leads to the text being differently displayed and users getting confused. Also this allows us to check if the file actually exists. BUG: 358221 FIXED-IN: 5.21 --- runners/locations/locationrunner.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/runners/locations/locationrunner.cpp b/runners/locations/locationrunner.cpp index 253028ee9..0512df1a2 100644 --- a/runners/locations/locationrunner.cpp +++ b/runners/locations/locationrunner.cpp @@ -53,29 +53,23 @@ LocationsRunner::~LocationsRunner() void LocationsRunner::match(Plasma::RunnerContext &context) { QString term = context.query(); - QUrl url(term); - const bool isLocalFile = url.isLocalFile(); - const QFileInfo fileInfo = QFileInfo(isLocalFile ? url.toLocalFile() : KShell::tildeExpand(term)); + // We want to expand ENV variables like $HOME to get the actual path, BUG: 358221 + KUriFilter::self()->filterUri(term, {QStringLiteral("kshorturifilter")}); + const QUrl url(term); + // The uri filter takes care of the shell expansion + const QFileInfo fileInfo = QFileInfo(url.toLocalFile()); if (fileInfo.exists()) { Plasma::QueryMatch match(this); match.setType(Plasma::QueryMatch::ExactMatch); - match.setText(i18n("Open %1", term)); + match.setText(i18n("Open %1", context.query())); match.setIconName(fileInfo.isFile() ? KIO::iconNameForUrl(url) : QStringLiteral("system-file-manager")); match.setRelevance(1); - match.setData(isLocalFile ? url : QUrl::fromLocalFile(fileInfo.absoluteFilePath())); + match.setData(url); match.setType(Plasma::QueryMatch::ExactMatch); context.addMatch(match); - } else if (!isLocalFile && !url.isEmpty()) { - if (!KUriFilter::self()->filterUri(term, {QStringLiteral("kshorturifilter")})) { - return; - } - - url = QUrl(term); // The KUriFilter changed the term - if (url.scheme().isEmpty() || url.isLocalFile()) { // We handled existend files above - return; - } + } else if (!url.isLocalFile() && !url.isEmpty() && !url.scheme().isEmpty()) { const QString protocol = url.scheme(); Plasma::QueryMatch match(this); match.setData(url);