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)
{
const QRegularExpression re(uR"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"_qs);
if (!name.isEmpty() && (name.indexOf(re) != 0))
{
qDebug() << "Incorrect category name:" << name;
return false;
}
return true;
const QRegularExpression re {uR"(^([^\\\/]|[^\\\/]([^\\\/]|\/(?=[^\/]))*[^\\\/])$)"_qs};
return (name.isEmpty() || (name.indexOf(re) == 0));
}
QStringList Session::expandCategory(const QString &category)
{
QStringList result;
if (!isValidCategoryName(category))
return result;
int 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
{
if (m_category.isEmpty()) return category.isEmpty();
if (!Session::isValidCategoryName(category)) return false;
if (m_category.isEmpty())
return category.isEmpty();
if (m_category == category) return true;
if (m_session->isSubcategoriesEnabled() && m_category.startsWith(category + u'/'))
if (m_category == category)
return true;
return false;
return (m_session->isSubcategoriesEnabled() && m_category.startsWith(category + u'/'));
}
TagSet TorrentImpl::tags() const