Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/library/searchquery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
#include "util/db/sqllikewildcards.h"

namespace {
const QRegularExpression kDurationRegex(QStringLiteral("^(\\d*)(m|:)?([0-6]?\\d)?s?$"));
const QRegularExpression kNumericOperatorRegex(QStringLiteral("^(>|>=|=|<|<=)(.*)$"));
const QRegularExpression kDurationRegex(QStringLiteral("^(\\d+)(m|:)?([0-5]?\\d)?s?$"));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the change from 0-6 to 0-5 intentional?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, :00-:59 is the valid range. I also added a test that checks that :60 is not accepted.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex was wrong and no one ever noticed.


// The ordering of operator alternatives separated by '|' is crucial to avoid incomplete
// partial matches, e.g. by capturing "<" + "=" + <arg> instead of "<=" + <arg>!
//
// See also: https://perldoc.perl.org/perlre
// > Alternatives are tried from left to right, so the first alternative found for which
// > the entire expression matches, is the one that is chosen. This means that alternatives
// > are not necessarily greedy.
const QRegularExpression kNumericOperatorRegex(QStringLiteral("^(<=|>=|=|<|>)(.*)$"));
} // namespace

QVariant getTrackValueForColumn(const TrackPointer& pTrack, const QString& column) {
Expand Down
6 changes: 6 additions & 0 deletions src/test/searchqueryparsertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,12 @@ TEST_F(SearchQueryParserTest, HumanReadableDurationSearchWithOperators) {
EXPECT_STREQ(
qPrintable(QString("duration >= 63")),
qPrintable(pQuery->toSql()));

// Seconds out of range
pQuery = m_parser.parseQuery("duration:>=1:60", searchColumns, "");
pTrack->setDuration(60);
EXPECT_FALSE(pQuery->match(pTrack));
EXPECT_TRUE(pQuery->toSql().isEmpty());
}

TEST_F(SearchQueryParserTest, HumanReadableDurationSearchwithRangeFilter) {
Expand Down