From 19f926d669806379fe12b0eb3c5adabcde754845 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 24 Jun 2023 17:19:01 +0300 Subject: [PATCH] kurifilter-plugins: fix matching of mail links it was broken before the fork and sill is far from perfect due to the pattern being limited to fully qualified mail links but then again - is foo@bar.com link to mail without the "mailto:" or link to website with user? Signed-off-by: Ivailo Monev --- .../shorturi/kshorturifilter.cpp | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/kurifilter-plugins/shorturi/kshorturifilter.cpp b/kurifilter-plugins/shorturi/kshorturifilter.cpp index c9408bf6..1f6419c9 100644 --- a/kurifilter-plugins/shorturi/kshorturifilter.cpp +++ b/kurifilter-plugins/shorturi/kshorturifilter.cpp @@ -118,6 +118,13 @@ bool KShortUriFilter::filterUri( KUriFilterData& data ) const KUrl url = data.uri(); QString cmd = data.typedString(); + /* + * Extra match to be performed on the path for mailto:foo@bar.baz, the + * pattern for it requires fully qualified mail link (without the scheme) but + * the URL includes the scheme + */ + QString cmd2 = url.path(); + // WORKAROUND: Allow the use of '@' in the username component of a URL since // other browsers such as firefox in their infinite wisdom allow such blatant // violations of RFC 3986. BR# 69326/118413. @@ -416,7 +423,7 @@ bool KShortUriFilter::filterUri( KUriFilterData& data ) const { if (hint.regexp.indexIn(cmd) == 0) { - //kDebug(7023) << "match - prepending" << (*it).prepend; + //kDebug(7023) << "match - prepending" << hint.prepend; const QString cmdStr = hint.prepend + cmd; KUrl url(cmdStr); if (KProtocolInfo::isKnownProtocol(url)) @@ -428,6 +435,23 @@ bool KShortUriFilter::filterUri( KUriFilterData& data ) const } } + // NOTE: match for mailto:foo@bar.baz + Q_FOREACH(const URLHint& hint, m_urlHints) + { + if (hint.regexp.indexIn(cmd2) == 0) + { + //kDebug(7023) << "match - prepending" << hint.prepend; + const QString cmdStr = hint.prepend + cmd2; + KUrl url(cmdStr); + if (KProtocolInfo::isKnownProtocol(url)) + { + setFilteredUri( data, url ); + setUriType( data, hint.type ); + return true; + } + } + } + // No protocol and not malformed means a valid short URL such as kde.org or // user@192.168.0.1. However, it might also be valid only because it lacks // the scheme component, e.g. www.kde,org (illegal ',' before 'org'). The