Commit feb9e94d authored by Stefano Crocco's avatar Stefano Crocco
Browse files

Improve behavior when kfmclient openURL is launched with invalid URL

If kfmclient openURL is launched with an invalid URL, filteredURL will
return an empty URL which causes Konqueror to display an "Undocumented
error" error message.

To avoid this, when filteredUrl returns an empty URL, use the user's
home URL, as if no URL had been specified. In this case we also ignore
the mimetype requested by the user (if any) because in most cases it
won't be correct for the new URL.

This situation can be triggered if the user clicks on the
`kfmclient_html.desktop` file. In theory, this shouldn't happen; however,
currently it's happening quite often, as can be seen, for example,
from [this bug report](https://bugs.kde.org/show_bug.cgi?id=453822)).
As far as I could discover, this bug happens because the application launcher
puts `kfmclient_html.desktop` in the "Favorites" section instead of `konqbrowser.desktop`.
Clicking on it executes `kfmclient openURL %u text/html`, passing a literal `%u` as argument.
Since `%u` isn't a valid URL, the behavior described above occurs.

While the correct fix for the bug itself is to find out why the application launcher uses `kfmclient_html.desktop`,
I think that `kfmclient` should nonetheless have a more user-friendly behavior in case an invalid URL is given.


(cherry picked from commit 1d8a39a1)
parent 5961e07c
Pipeline #264899 passed with stage
in 9 minutes
......@@ -7,7 +7,6 @@
#include "kfmclient.h"
#include <kio/job.h>
#include <kio/jobuidelegate.h>
#include <KLocalizedString>
#include <kprocess.h>
......@@ -145,10 +144,7 @@ static QUrl filteredUrl(const QString &url)
data.setAbsolutePath(QDir::currentPath());
data.setCheckForExecutables(false);
if (KUriFilter::self()->filterUri(data) && data.uriType() != KUriFilterData::Error) {
return data.uri();
}
return QUrl();
return data.uri();
}
ClientApp::ClientApp()
......@@ -292,15 +288,18 @@ bool ClientApp::doIt(const QCommandLineParser &parser)
if (command == QLatin1String("openURL") || command == QLatin1String("newTab")) {
checkArgumentCount(argc, 1, 3);
const bool tempFile = parser.isSet(QStringLiteral("tempfile"));
if (argc == 1) {
return createNewWindow(QUrl::fromLocalFile(QDir::homePath()), command == QLatin1String("newTab"), tempFile);
}
if (argc == 2) {
return createNewWindow(filteredUrl(args.at(1)), command == QLatin1String("newTab"), tempFile);
}
if (argc == 3) {
return createNewWindow(filteredUrl(args.at(1)), command == QLatin1String("newTab"), tempFile, args.at(2));
QUrl url = argc > 1 ? filteredUrl(args.at(1)) : QUrl();
//If the given URL is empty an "Undocumented error" error page would be displayed.
//To avoid this, default to the user's home directory, as if no URL had been given
if (url.isEmpty()) {
url = QUrl::fromLocalFile(QDir::homePath());
}
QString mimetype = argc == 3 ? args.at(2) : QString();
return createNewWindow(url, command == QLatin1String("newTab"), tempFile, mimetype);
} else if (command == QLatin1String("openProfile")) { // deprecated command, kept for compat
checkArgumentCount(argc, 2, 3);
QUrl url;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment