Skip to content

Commit

Permalink
Make mailto: URLs matching stricter
Browse files Browse the repository at this point in the history
So that it doesn't hit when an email-like construct occurs inside a URL.
  • Loading branch information
KitsuneRal committed Aug 15, 2023
1 parent 42b888e commit 4f950d9
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Quotient/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ void Quotient::linkifyUrls(QString& htmlEscapedText)
QStringLiteral(
R"(\b((www\.(?!\.)(?!(\w|\.|-)+@)|(https?|ftp):(//)?\w|(magnet|matrix):)(&(?![lg]t;)|[^&\s<>'"])+(&(?![lg]t;)|[^&!,.\s<>'"\]):])))"),
RegExpOptions);
// email address:
// [word chars, dots or dashes]@[word chars, dots or dashes].[word chars]
static const QRegularExpression EmailAddressRegExp(
QStringLiteral(R"(\b(mailto:)?((\w|\.|-)+@(\w|\.|-)+\.\w+\b))"),
QStringLiteral(R"((^|[][[:space:](){}`'";<>])(mailto:)?((\w|[!#$%&'*+=^_‘{|}~.-])+@(\w|\.|-)+\.\w+\b))"),
RegExpOptions);
// An interim liberal implementation of
// https://matrix.org/docs/spec/appendices.html#identifier-grammar
Expand All @@ -49,7 +47,7 @@ void Quotient::linkifyUrls(QString& htmlEscapedText)
// NOTE: htmlEscapedText is already HTML-escaped! No literal <,>,&,"

htmlEscapedText.replace(EmailAddressRegExp,
R"(<a href='mailto:\2'>\1\2</a>)"_ls);
R"(\1<a href='mailto:\3'>\2\3</a>)"_ls);
htmlEscapedText.replace(FullUrlRegExp, R"(<a href='\1'>\1</a>)"_ls);
htmlEscapedText.replace(MxIdRegExp,
R"(\1<a href='https://matrix.to/#/\2'>\2</a>)"_ls);
Expand Down

0 comments on commit 4f950d9

Please sign in to comment.