RSS: Fix crash when moving a folder into its subfolder

Closes #18446.
This commit is contained in:
Vladimir Golovnev (Glassez) 2025-03-26 19:30:55 +03:00
commit edf9e6a129
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7

View file

@ -214,14 +214,20 @@ nonstd::expected<void, QString> Session::moveItem(Item *item, const QString &des
Q_ASSERT(item); Q_ASSERT(item);
Q_ASSERT(item != rootFolder()); Q_ASSERT(item != rootFolder());
if (item->path() == destPath)
return {};
if (auto *folder = static_cast<Folder *>(item)) // if `item` is a `Folder`
{
if (destPath.startsWith(folder->path() + Item::PathSeparator))
return nonstd::make_unexpected(tr("Couldn't move folder into itself or its subfolder."));
}
const nonstd::expected<Folder *, QString> result = prepareItemDest(destPath); const nonstd::expected<Folder *, QString> result = prepareItemDest(destPath);
if (!result) if (!result)
return result.get_unexpected(); return result.get_unexpected();
auto *destFolder = result.value(); auto *destFolder = result.value();
if (static_cast<Item *>(destFolder) == item)
return nonstd::make_unexpected(tr("Couldn't move folder into itself."));
auto *srcFolder = static_cast<Folder *>(m_itemsByPath.value(Item::parentPath(item->path()))); auto *srcFolder = static_cast<Folder *>(m_itemsByPath.value(Item::parentPath(item->path())));
if (srcFolder != destFolder) if (srcFolder != destFolder)
{ {