mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-02 13:48:05 -06:00
Block invalid file names when renaming torrent content
Relevant issues: #22426, #21899,#16906,#16834, #16271, #11276, #9085, #11340, #14728, #20412, #20337, #17049, #17752, #17469, #15378, #15227, #14908. PR #23060. --------- Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
#include <functional>
|
||||
|
||||
#include <QBitArray>
|
||||
#include <QFileInfo>
|
||||
#include <QFuture>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
@@ -1990,6 +1991,10 @@ void TorrentsController::renameFileAction()
|
||||
{
|
||||
requireParams({u"hash"_s, u"oldPath"_s, u"newPath"_s});
|
||||
|
||||
const QString newFileName = QFileInfo(params()[u"newPath"_s]).fileName();
|
||||
if (!Utils::Fs::isValidName(newFileName))
|
||||
throw APIError(APIErrorType::Conflict, tr("File name has invalid characters"));
|
||||
|
||||
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]);
|
||||
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
|
||||
if (!torrent)
|
||||
@@ -2014,6 +2019,10 @@ void TorrentsController::renameFolderAction()
|
||||
{
|
||||
requireParams({u"hash"_s, u"oldPath"_s, u"newPath"_s});
|
||||
|
||||
const QString newFolderName = QFileInfo(params()[u"newPath"_s]).fileName();
|
||||
if (!Utils::Fs::isValidName(newFolderName))
|
||||
throw APIError(APIErrorType::Conflict, tr("Folder name has invalid characters"));
|
||||
|
||||
const auto id = BitTorrent::TorrentID::fromString(params()[u"hash"_s]);
|
||||
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->getTorrent(id);
|
||||
if (!torrent)
|
||||
|
||||
Reference in New Issue
Block a user