diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2019-05-01 12:11:19 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2019-05-01 12:11:19 +0200 |
commit | 23eef9e1bcbb7a9ada18d55a9198aa13903e571a (patch) | |
tree | 9d44ca34e1df056a20f4f1e95c5831843ca98170 /src/Config.h | |
parent | Merge pull request #58 from zapashcanon/sh (diff) | |
download | nheko-23eef9e1bcbb7a9ada18d55a9198aa13903e571a.tar.xz |
Simplify linkifyMessage
Parsing html as xml has inherent problems, most notable there are many matrix clients that don't escape ampersands in urls of mx-replies, etc. (See issue #18) This also removes the replacement of <mx-reply> as it isn't strictly needed. Also the QRegExp is replaced with the Qt5 QRegularExpression for perfomance and because it supports lookahead and lookbehind. I'm pretty sure that the original code also replaced href="" with href=\"\", which was probably wrong, but I'm not to sure about that. Fixes #18
Diffstat (limited to 'src/Config.h')
-rw-r--r-- | src/Config.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/Config.h b/src/Config.h index bb99ca87..6aebb51b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -1,6 +1,6 @@ #pragma once -#include <QRegExp> +#include <QRegularExpression> #include <QString> // Non-theme app configuration. Layouts, fonts spacing etc. @@ -51,8 +51,11 @@ constexpr auto LABEL_BIG_SIZE_RATIO = 2; namespace strings { const QString url_html = "<a href=\"\\1\">\\1</a>"; -const QRegExp url_regex( - "((www\\.(?!\\.)|[a-z][a-z0-9+.-]*://)[^\\s<>'\"]+[^!,\\.\\s<>'\"\\]\\)\\:])"); +const QRegularExpression url_regex( + // match an URL, that is not quoted, i.e. + // vvvvvv match quote via negative lookahead/lookbehind vvvvv + // vvvv atomic match url -> fail if there is a " before or after vv + R"regex((?<!")(?>((www\.(?!\.)|[a-z][a-z0-9+.-]*://)[^\s<>'"]+[^!,\.\s<>'"\]\)\:]))(?!"))regex"); } // Window geometry. |