Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use non-capturing group for highlight boundaries #5784

Merged
merged 4 commits into from
Jan 12, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Bugfix: Fixed a crash that could occur on Linux and macOS when clicking "Install" from the update prompt. (#5818)
- Bugfix: Fixed missing word wrap in update popup. (#5811)
- Bugfix: Fixed tabs not scaling to the default scale when changing the scale from a non-default value. (#5794)
- Dev: Highlight checks now use non-capturing groups for the boundaries. (#5784)
- Dev: Updated Conan dependencies. (#5776)

## 2.5.2
Expand Down
10 changes: 6 additions & 4 deletions src/controllers/highlights/HighlightPhrase.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "controllers/highlights/HighlightPhrase.hpp"

#include <QStringBuilder>

namespace chatterino {

namespace {

const QString REGEX_START_BOUNDARY("(\\b|\\s|^)");
const QString REGEX_END_BOUNDARY("(\\b|\\s|$)");
constexpr QStringView REGEX_START_BOUNDARY(u"(?:\\b|\\s|^)");
constexpr QStringView REGEX_END_BOUNDARY(u"(?:\\b|\\s|$)");

} // namespace

Expand Down Expand Up @@ -46,7 +48,7 @@ HighlightPhrase::HighlightPhrase(const QString &pattern, bool showInMentions,
, soundUrl_(soundUrl)
, regex_(isRegex_
? pattern
: REGEX_START_BOUNDARY + QRegularExpression::escape(pattern) +
: REGEX_START_BOUNDARY % QRegularExpression::escape(pattern) %
REGEX_END_BOUNDARY,
QRegularExpression::UseUnicodePropertiesOption |
(isCaseSensitive_ ? QRegularExpression::NoPatternOption
Expand All @@ -69,7 +71,7 @@ HighlightPhrase::HighlightPhrase(const QString &pattern, bool showInMentions,
, color_(std::move(color))
, regex_(isRegex_
? pattern
: REGEX_START_BOUNDARY + QRegularExpression::escape(pattern) +
: REGEX_START_BOUNDARY % QRegularExpression::escape(pattern) %
REGEX_END_BOUNDARY,
QRegularExpression::UseUnicodePropertiesOption |
(isCaseSensitive_ ? QRegularExpression::NoPatternOption
Expand Down
Loading