diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-03-24 18:51:08 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-03-24 18:53:26 +0900 |
commit | 21e5138f6cf1e96d3cac702e2ada2a0148a3ec92 (patch) | |
tree | c98bc4efeefb8b22ee555b9ad8dcc74855c413bb /lib | |
parent | 9ba481f2c8e7f1db6144ece7119d8cc314c57bc5 (diff) | |
download | libquotient-21e5138f6cf1e96d3cac702e2ada2a0148a3ec92.tar.gz libquotient-21e5138f6cf1e96d3cac702e2ada2a0148a3ec92.zip |
linkifyUrls(): fix linkification of emails containing "www."
Closes #303.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/util.cpp b/lib/util.cpp index d042aa34..e1f312ee 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -38,14 +38,14 @@ static void linkifyUrls(QString& htmlEscapedText) // comma or dot // Note: outer parentheses are a part of C++ raw string delimiters, not of // the regex (see http://en.cppreference.com/w/cpp/language/string_literal). - // Note2: yet another pair of outer parentheses are \1 in the replacement. + // Note2: the next-outer parentheses are \N in the replacement. static const QRegularExpression FullUrlRegExp(QStringLiteral( - R"(((www\.(?!\.)|(https?|ftp|magnet)://)(&(?![lg]t;)|[^&\s<>'"])+(&(?![lg]t;)|[^&!,.\s<>'"\]):])))" + R"(\b((www\.(?!\.)(?!(\w|\.|-)+@)|(https?|ftp|magnet)://)(&(?![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"((mailto:)?(\b(\w|\.|-)+@(\w|\.|-)+\.\w+\b))" + R"(\b(mailto:)?((\w|\.|-)+@(\w|\.|-)+\.\w+\b))" ), RegExpOptions); // An interim liberal implementation of // https://matrix.org/docs/spec/appendices.html#identifier-grammar @@ -53,7 +53,7 @@ static void linkifyUrls(QString& htmlEscapedText) R"((^|[^<>/])([!#@][-a-z0-9_=/.]{1,252}:[-.a-z0-9]+))" ), RegExpOptions); - // NOTE: htmlEscapedText is already HTML-escaped! No literal <,>,& + // NOTE: htmlEscapedText is already HTML-escaped! No literal <,>,&," htmlEscapedText.replace(EmailAddressRegExp, QStringLiteral(R"(<a href="mailto:\2">\1\2</a>)")); |