From ec85b9352febb982dd02469635d0553901acce4d Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Sun, 3 Oct 2021 19:43:03 +0200 Subject: prettyPrint(): tighten up Matrix identifier regex It was too permissive on characters before the identifier and also allowed the domain name to start on dash, which should not occur. Closes #512. --- lib/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/util.cpp') diff --git a/lib/util.cpp b/lib/util.cpp index 875d7522..5de8638e 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -58,7 +58,7 @@ void Quotient::linkifyUrls(QString& htmlEscapedText) // https://matrix.org/docs/spec/appendices.html#identifier-grammar static const QRegularExpression MxIdRegExp( QStringLiteral( - R"((^|[^<>/])([!#@][-a-z0-9_=#/.]{1,252}:(?:\w|\.|-)+\.\w+(?::\d{1,5})?))"), + R"((^|[][[:space:](){}`'";])([!#@][-a-z0-9_=#/.]{1,252}:\w(?:\w|\.|-)*\.\w+(?::\d{1,5})?))"), RegExpOptions); Q_ASSERT(FullUrlRegExp.isValid() && EmailAddressRegExp.isValid() && MxIdRegExp.isValid()); -- cgit v1.2.3 From 88cbbe5eb2e024d71e0897617ab65860cee51607 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Mon, 4 Oct 2021 09:53:53 +0200 Subject: Further tighten the linkifier in prettyPrint() --- lib/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/util.cpp') diff --git a/lib/util.cpp b/lib/util.cpp index 5de8638e..cf5e81a3 100644 --- a/lib/util.cpp +++ b/lib/util.cpp @@ -47,7 +47,7 @@ void Quotient::linkifyUrls(QString& htmlEscapedText) // comma or dot static const QRegularExpression FullUrlRegExp( QStringLiteral( - R"(\b((www\.(?!\.)(?!(\w|\.|-)+@)|(https?|ftp|magnet|matrix):(//)?)(&(?![lg]t;)|[^&\s<>'"])+(&(?![lg]t;)|[^&!,.\s<>'"\]):])))"), + 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] -- cgit v1.2.3