Changeset View
Changeset View
Standalone View
Standalone View
src/urifilters/localdomain/localdomainurifilter.cpp
Show All 24 Lines | |||||
25 | #include <KPluginFactory> | 25 | #include <KPluginFactory> | ||
26 | 26 | | |||
27 | #include <QHostInfo> | 27 | #include <QHostInfo> | ||
28 | #include <QLoggingCategory> | 28 | #include <QLoggingCategory> | ||
29 | 29 | | |||
30 | #define QL1C(x) QLatin1Char(x) | 30 | #define QL1C(x) QLatin1Char(x) | ||
31 | #define QL1S(x) QLatin1String(x) | 31 | #define QL1S(x) QLatin1String(x) | ||
32 | 32 | | |||
33 | #define HOSTPORT_PATTERN "[a-zA-Z0-9][a-zA-Z0-9+-]*(?:\\:[0-9]{1,5})?(?:/[\\w:@&=+$,-.!~*'()]*)*" | | |||
34 | | ||||
35 | namespace { | 33 | namespace { | ||
36 | QLoggingCategory category("org.kde.kurifilter-localdomain", QtWarningMsg); | 34 | QLoggingCategory category("org.kde.kurifilter-localdomain", QtWarningMsg); | ||
37 | } | 35 | } | ||
38 | 36 | | |||
39 | /** | 37 | /** | ||
40 | * IMPORTANT: If you change anything here, make sure you run the kurifiltertest | 38 | * IMPORTANT: If you change anything here, make sure you run the kurifiltertest | ||
41 | * regression test (this should be included as part of "make test"). | 39 | * regression test (this should be included as part of "make test"). | ||
42 | */ | 40 | */ | ||
43 | LocalDomainUriFilter::LocalDomainUriFilter(QObject *parent, const QVariantList & /*args*/) | 41 | LocalDomainUriFilter::LocalDomainUriFilter(QObject *parent, const QVariantList & /*args*/) | ||
44 | : KUriFilterPlugin(QStringLiteral("localdomainurifilter"), parent) | 42 | : KUriFilterPlugin(QStringLiteral("localdomainurifilter"), parent) | ||
45 | , m_hostPortPattern(QL1S(HOSTPORT_PATTERN)) | | |||
46 | { | 43 | { | ||
44 | m_hostPortPattern = QRegularExpression(QRegularExpression::anchoredPattern( | ||||
45 | QStringLiteral("[a-zA-Z0-9][a-zA-Z0-9+-]*(?:\\:[0-9]{1,5})?(?:/[\\w:@&=+$,-.!~*'()]*)*"))); | ||||
47 | } | 46 | } | ||
48 | 47 | | |||
49 | bool LocalDomainUriFilter::filterUri(KUriFilterData &data) const | 48 | bool LocalDomainUriFilter::filterUri(KUriFilterData &data) const | ||
50 | { | 49 | { | ||
51 | const QUrl url = data.uri(); | 50 | const QUrl url = data.uri(); | ||
52 | const QString protocol = url.scheme(); | 51 | const QString protocol = url.scheme(); | ||
53 | 52 | | |||
54 | // When checking for local domain just validate it is indeed a local domain, | 53 | // When checking for local domain just validate it is indeed a local domain, | ||
55 | // but do not modify the hostname! See bug# | 54 | // but do not modify the hostname! See bug# | ||
56 | if ((protocol.isEmpty() || !KProtocolInfo::isKnownProtocol(protocol)) | 55 | if ((protocol.isEmpty() || !KProtocolInfo::isKnownProtocol(protocol)) | ||
57 | && m_hostPortPattern.exactMatch(data.typedString())) { | 56 | && m_hostPortPattern.match(data.typedString()).hasMatch()) { | ||
58 | QString host(data.typedString().left(data.typedString().indexOf(QL1C('/')))); | 57 | QString host(data.typedString().left(data.typedString().indexOf(QL1C('/')))); | ||
59 | const int pos = host.indexOf(QL1C(':')); | 58 | const int pos = host.indexOf(QL1C(':')); | ||
60 | if (pos > -1) { | 59 | if (pos > -1) { | ||
61 | host.truncate(pos); // Remove port number | 60 | host.truncate(pos); // Remove port number | ||
62 | } | 61 | } | ||
63 | if (exists(host)) { | 62 | if (exists(host)) { | ||
64 | qCDebug(category) << "QHostInfo found a host called" << host; | 63 | qCDebug(category) << "QHostInfo found a host called" << host; | ||
65 | QString scheme(data.defaultUrlScheme()); | 64 | QString scheme(data.defaultUrlScheme()); | ||
Show All 22 Lines |