Escape regexp meta-characters in search strings

This resolves the regression where Highlight Callsign UDP messages
fail when the callsign contains a '+' character.
This commit is contained in:
Bill Somerville 2020-06-04 03:41:11 +01:00
parent c30c3ce4c8
commit a8115a9000
No known key found for this signature in database
GPG Key ID: D864B06D1E81618F

View File

@ -553,7 +553,14 @@ void DisplayText::highlight_callsign (QString const& callsign, QColor const& bg,
{
return;
}
QRegularExpression target {QString {"<?"} + callsign + QString {">?"}, QRegularExpression::DontCaptureOption};
auto regexp = callsign;
// allow for hashed callsigns and escape any regexp metacharacters
QRegularExpression target {QString {"<?"}
+ regexp.replace (QLatin1Char {'+'}, QLatin1String {"\\+"})
.replace (QLatin1Char {'.'}, QLatin1String {"\\."})
.replace (QLatin1Char {'?'}, QLatin1String {"\\?"})
+ QString {">?"}
, QRegularExpression::DontCaptureOption};
QTextCharFormat old_format {currentCharFormat ()};
QTextCursor cursor {document ()};
if (last_period_only)