mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
Add validation to block renaming to invalid names (e.g., '.', '..', control chars, length > 255)
This commit is contained in:
parent
fef6ac515c
commit
abd6d1f2f4
1 changed files with 22 additions and 2 deletions
|
@ -54,6 +54,8 @@
|
|||
#include "base/global.h"
|
||||
#include "base/path.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "torrentcontentmodelfile.h"
|
||||
#include "torrentcontentmodelfolder.h"
|
||||
#include "torrentcontentmodelitem.h"
|
||||
|
@ -299,9 +301,27 @@ bool TorrentContentModel::setData(const QModelIndex &index, const QVariant &valu
|
|||
case TorrentContentModelItem::COL_NAME:
|
||||
{
|
||||
const QString currentName = item->name();
|
||||
const QString newName = value.toString();
|
||||
QString newName = value.toString().trimmed();
|
||||
if (currentName != newName)
|
||||
{
|
||||
bool invalid = newName.isEmpty() || (newName == u"."_s) || (newName == u".."_s) || (newName.length() > 255);
|
||||
if (!invalid)
|
||||
{
|
||||
for (const QChar &c : newName)
|
||||
{
|
||||
const ushort unicode = c.unicode();
|
||||
if ((unicode < 32) || (unicode == 127) || (c == u'<') || (c == u'>') || (c == u':') || (c == u'"') || (c == u'/') || (c == u'\\') || (c == u'|') || (c == u'?') || (c == u'*'))
|
||||
{
|
||||
invalid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (invalid)
|
||||
{
|
||||
emit renameFailed(tr("The name \"%1\" is invalid.").arg(newName));
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
const Path parentPath = getItemPath(index.parent());
|
||||
|
@ -710,4 +730,4 @@ void TorrentContentModel::notifySubtreeUpdated(const QModelIndex &index, const Q
|
|||
parentIndexes.push_back(sibling);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue