mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-10-22 18:56:08 +03:00
Merge pull request #11194 from Chocobo1/filename
Fix filename validation on non-Windows OS
This commit is contained in:
commit
ee0f38a696
2 changed files with 15 additions and 3 deletions
|
@ -230,7 +230,19 @@ bool Utils::Fs::isValidFileSystemName(const QString &name, const bool allowSepar
|
||||||
{
|
{
|
||||||
if (name.isEmpty()) return false;
|
if (name.isEmpty()) return false;
|
||||||
|
|
||||||
const QRegularExpression regex(allowSeparators ? "[:?\"*<>|]" : "[\\\\/:?\"*<>|]");
|
#if defined(Q_OS_WIN)
|
||||||
|
const QRegularExpression regex {allowSeparators
|
||||||
|
? QLatin1String("[:?\"*<>|]")
|
||||||
|
: QLatin1String("[\\\\/:?\"*<>|]")};
|
||||||
|
#elif defined(Q_OS_MACOS)
|
||||||
|
const QRegularExpression regex {allowSeparators
|
||||||
|
? QLatin1String("[\\0:]")
|
||||||
|
: QLatin1String("[\\0/:]")};
|
||||||
|
#else
|
||||||
|
const QRegularExpression regex {allowSeparators
|
||||||
|
? QLatin1String("[\\0]")
|
||||||
|
: QLatin1String("[\\0/]")};
|
||||||
|
#endif
|
||||||
return !name.contains(regex);
|
return !name.contains(regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ void TorrentContentTreeView::renameSelectedFile(BitTorrent::TorrentHandle *torre
|
||||||
, modelIndex.data().toString(), &ok, isFile).trimmed();
|
, modelIndex.data().toString(), &ok, isFile).trimmed();
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|
||||||
if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) {
|
if (!Utils::Fs::isValidFileSystemName(newName)) {
|
||||||
RaisedMessageBox::warning(this, tr("Rename error"),
|
RaisedMessageBox::warning(this, tr("Rename error"),
|
||||||
tr("The name is empty or contains forbidden characters, please choose a different one."),
|
tr("The name is empty or contains forbidden characters, please choose a different one."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
@ -227,7 +227,7 @@ void TorrentContentTreeView::renameSelectedFile(BitTorrent::TorrentInfo &torrent
|
||||||
, modelIndex.data().toString(), &ok, isFile).trimmed();
|
, modelIndex.data().toString(), &ok, isFile).trimmed();
|
||||||
if (!ok) return;
|
if (!ok) return;
|
||||||
|
|
||||||
if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) {
|
if (!Utils::Fs::isValidFileSystemName(newName)) {
|
||||||
RaisedMessageBox::warning(this, tr("Rename error"),
|
RaisedMessageBox::warning(this, tr("Rename error"),
|
||||||
tr("The name is empty or contains forbidden characters, please choose a different one."),
|
tr("The name is empty or contains forbidden characters, please choose a different one."),
|
||||||
QMessageBox::Ok);
|
QMessageBox::Ok);
|
||||||
|
|
Loading…
Reference in a new issue