1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-02-02 09:55:55 +00:00

Avoid redundant checks of category names

PR #17130.
This commit is contained in:
Vladimir Golovnev 2022-05-31 10:42:40 +03:00 committed by GitHub
parent 5173a56ebd
commit ab0c82965c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 17 deletions

View File

@ -635,22 +635,13 @@ Path Session::downloadPath() const
bool Session::isValidCategoryName(const QString &name) bool Session::isValidCategoryName(const QString &name)
{ {
const QRegularExpression re(uR"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"_qs); const QRegularExpression re {uR"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"_qs};
if (!name.isEmpty() && (name.indexOf(re) != 0)) return (name.isEmpty() || (name.indexOf(re) == 0));
{
qDebug() << "Incorrect category name:" << name;
return false;
}
return true;
} }
QStringList Session::expandCategory(const QString &category) QStringList Session::expandCategory(const QString &category)
{ {
QStringList result; QStringList result;
if (!isValidCategoryName(category))
return result;
int index = 0; int index = 0;
while ((index = category.indexOf(u'/', index)) >= 0) while ((index = category.indexOf(u'/', index)) >= 0)
{ {

View File

@ -717,15 +717,13 @@ QString TorrentImpl::category() const
bool TorrentImpl::belongsToCategory(const QString &category) const bool TorrentImpl::belongsToCategory(const QString &category) const
{ {
if (m_category.isEmpty()) return category.isEmpty(); if (m_category.isEmpty())
if (!Session::isValidCategoryName(category)) return false; return category.isEmpty();
if (m_category == category) return true; if (m_category == category)
if (m_session->isSubcategoriesEnabled() && m_category.startsWith(category + u'/'))
return true; return true;
return false; return (m_session->isSubcategoriesEnabled() && m_category.startsWith(category + u'/'));
} }
TagSet TorrentImpl::tags() const TagSet TorrentImpl::tags() const