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:
cocopaw
2025-09-20 16:42:30 +10:00
committed by GitHub
parent 753fb80e9b
commit 9696c99dbd
4 changed files with 72 additions and 1 deletions

View File

@@ -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)