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 <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-24 17:19:01 +03:00
parent 5b7845d814
commit 19f926d669

View file

@ -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