mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-26 06:26:11 -05:00
Add support for opening file:// urls (#2311)
* Add support for opening file:// urls * Open file urls without file:// scheme
This commit is contained in:
parent
341635f6bd
commit
f8b997bcf4
@ -26,6 +26,7 @@
|
||||
#include "totp/totp.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
|
||||
const int Entry::DefaultIconNumber = 0;
|
||||
@ -986,12 +987,13 @@ Entry::PlaceholderType Entry::placeholderType(const QString& placeholder) const
|
||||
QString Entry::resolveUrl(const QString& url) const
|
||||
{
|
||||
QString newUrl = url;
|
||||
if (!url.isEmpty() && !url.contains("://")) {
|
||||
// URL doesn't have a protocol, add https by default
|
||||
newUrl.prepend("https://");
|
||||
}
|
||||
|
||||
if (newUrl.startsWith("cmd://")) {
|
||||
QRegExp fileRegEx("^([a-z]:)?[\\\\/]", Qt::CaseInsensitive, QRegExp::RegExp2);
|
||||
if (fileRegEx.indexIn(newUrl) != -1) {
|
||||
// Match possible file paths without the scheme and convert it to a file URL
|
||||
newUrl = QDir::fromNativeSeparators(newUrl);
|
||||
newUrl = QUrl::fromLocalFile(newUrl).toString();
|
||||
} else if (newUrl.startsWith("cmd://")) {
|
||||
QStringList cmdList = newUrl.split(" ");
|
||||
for (int i = 1; i < cmdList.size(); ++i) {
|
||||
// Don't pass arguments to the resolveUrl function (they look like URL's)
|
||||
@ -1004,9 +1006,14 @@ QString Entry::resolveUrl(const QString& url) const
|
||||
return QString("");
|
||||
}
|
||||
|
||||
if (!newUrl.isEmpty() && !newUrl.contains("://")) {
|
||||
// URL doesn't have a protocol, add https by default
|
||||
newUrl.prepend("https://");
|
||||
}
|
||||
|
||||
// Validate the URL
|
||||
QUrl tempUrl = QUrl(newUrl);
|
||||
if (tempUrl.isValid() && (tempUrl.scheme() == "http" || tempUrl.scheme() == "https")) {
|
||||
if (tempUrl.isValid() && (tempUrl.scheme() == "http" || tempUrl.scheme() == "https" || tempUrl.scheme() == "file")) {
|
||||
return tempUrl.url();
|
||||
}
|
||||
|
||||
|
@ -148,6 +148,8 @@ void TestEntry::testResolveUrl()
|
||||
QScopedPointer<Entry> entry(new Entry());
|
||||
QString testUrl("www.google.com");
|
||||
QString testCmd("cmd://firefox " + testUrl);
|
||||
QString testFileUnix("/home/example/test.txt");
|
||||
QString testFileWindows("c:/WINDOWS/test.txt");
|
||||
QString testComplexCmd("cmd://firefox --start-now --url 'http://" + testUrl + "' --quit");
|
||||
QString nonHttpUrl("ftp://google.com");
|
||||
QString noUrl("random text inserted here");
|
||||
@ -156,6 +158,11 @@ void TestEntry::testResolveUrl()
|
||||
QCOMPARE(entry->resolveUrl(""), QString(""));
|
||||
QCOMPARE(entry->resolveUrl(testUrl), "https://" + testUrl);
|
||||
QCOMPARE(entry->resolveUrl("http://" + testUrl), "http://" + testUrl);
|
||||
// Test file:// URL's
|
||||
QCOMPARE(entry->resolveUrl("file://" + testFileUnix), "file://" + testFileUnix);
|
||||
QCOMPARE(entry->resolveUrl(testFileUnix), "file://" + testFileUnix);
|
||||
QCOMPARE(entry->resolveUrl("file:///" + testFileWindows), "file:///" + testFileWindows);
|
||||
QCOMPARE(entry->resolveUrl(testFileWindows), "file:///" + testFileWindows);
|
||||
// Test cmd:// with no URL
|
||||
QCOMPARE(entry->resolveUrl("cmd://firefox"), QString(""));
|
||||
QCOMPARE(entry->resolveUrl("cmd://firefox --no-url"), QString(""));
|
||||
|
Loading…
x
Reference in New Issue
Block a user