Skip to content

Commit

Permalink
Consider brackets within wildcard as regular characters
Browse files Browse the repository at this point in the history
  • Loading branch information
vlakoff committed Jan 26, 2024
1 parent 94e80d0 commit 095bf83
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/base/utils/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ QString Utils::String::fromDouble(const double n, const int precision)

QString Utils::String::wildcardToRegexPattern(const QString &pattern)
{
return QRegularExpression::wildcardToRegularExpression(pattern, QRegularExpression::UnanchoredWildcardConversion);
QString wildcard = QRegularExpression::escape(pattern);

// Replace "\?" (which has been regex-escaped above) with "."
wildcard.replace(u"\\?"_s, u"."_s);

// Replace "\*" (which has been regex-escaped above) with ".*"
// Consecutive wildcards are merged to avoid catastrophic backtracking
wildcard.replace(QRegularExpression(u"(?:\\\\\\*)+"_s), u".*"_s);

return wildcard;
}

QStringList Utils::String::splitCommand(const QString &command)
Expand Down

0 comments on commit 095bf83

Please sign in to comment.