mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2026-11-25 19:41:37 -08:00
Show UI warning for invalid URLs
This commit is contained in:
1 parent
663393d994
commit
c0f29cc790
11 files changed
+211
-2
No files matched your search
@@ -32,6 +32,7 @@
|
||||
#include <QRegularExpression>
|
||||
#include <QStringList>
|
||||
#include <QSysInfo>
|
||||
#include <QUrl>
|
||||
#include <QUuid>
|
||||
#include <cctype>
|
||||
|
||||
@@ -259,6 +260,33 @@ namespace Tools
|
||||
}
|
||||
}
|
||||
|
||||
bool checkUrlValid(const QString& urlField)
|
||||
{
|
||||
if (urlField.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
QUrl url;
|
||||
if (urlField.contains("://")) {
|
||||
url = urlField;
|
||||
} else {
|
||||
url = QUrl::fromUserInput(urlField);
|
||||
}
|
||||
|
||||
if (url.scheme() != "file" && url.host().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for illegal characters. Adds also the wildcard * to the list
|
||||
QRegularExpression re("[<>\\^`{|}\\*]");
|
||||
auto match = re.match(urlField);
|
||||
if (match.hasMatch()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Escape common regex symbols except for *, ?, and |
|
||||
auto regexEscape = QRegularExpression(R"re(([-[\]{}()+.,\\\/^$#]))re");
|
||||
|
||||
|
||||
Reference in new issue
Block a user