Browse Source

Avoid redundant checks of category names

PR #17130.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
ab0c82965c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/base/bittorrent/session.cpp
  2. 10
      src/base/bittorrent/torrentimpl.cpp

13
src/base/bittorrent/session.cpp

@ -635,22 +635,13 @@ Path Session::downloadPath() const @@ -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)
{

10
src/base/bittorrent/torrentimpl.cpp

@ -717,15 +717,13 @@ QString TorrentImpl::category() const @@ -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

Loading…
Cancel
Save