From 9dc3b1817842fe0950997f64e91a0edaf172106b Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Thu, 5 Sep 2019 02:00:10 +0800 Subject: [PATCH] Fix filename validation on non-Windows OS Closes #11191. --- src/base/utils/fs.cpp | 14 +++++++++++++- src/gui/torrentcontenttreeview.cpp | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index 78aecf125..c3a19e2a9 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -230,7 +230,19 @@ bool Utils::Fs::isValidFileSystemName(const QString &name, const bool allowSepar { 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); } diff --git a/src/gui/torrentcontenttreeview.cpp b/src/gui/torrentcontenttreeview.cpp index af38e34d3..c79aaca17 100644 --- a/src/gui/torrentcontenttreeview.cpp +++ b/src/gui/torrentcontenttreeview.cpp @@ -108,7 +108,7 @@ void TorrentContentTreeView::renameSelectedFile(BitTorrent::TorrentHandle *torre , modelIndex.data().toString(), &ok, isFile).trimmed(); if (!ok) return; - if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) { + if (!Utils::Fs::isValidFileSystemName(newName)) { RaisedMessageBox::warning(this, tr("Rename error"), tr("The name is empty or contains forbidden characters, please choose a different one."), QMessageBox::Ok); @@ -227,7 +227,7 @@ void TorrentContentTreeView::renameSelectedFile(BitTorrent::TorrentInfo &torrent , modelIndex.data().toString(), &ok, isFile).trimmed(); if (!ok) return; - if (newName.isEmpty() || !Utils::Fs::isValidFileSystemName(newName)) { + if (!Utils::Fs::isValidFileSystemName(newName)) { RaisedMessageBox::warning(this, tr("Rename error"), tr("The name is empty or contains forbidden characters, please choose a different one."), QMessageBox::Ok);