diff options
author | Lars Knoll <lars.knoll@qt.io> | 2016-08-26 13:39:14 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2016-10-11 14:20:27 +0000 |
commit | 369857d29437615e1fda9fb1ab2f94e464d55ca2 (patch) | |
tree | 5efb1e47561de6a36da3f2c91b01726321b4dac6 /src | |
parent | 5574a814ff7d4932c817618c34e80f3c61887e26 (diff) |
Add configure feature for QUrl::topLevelDomain
Change-Id: I237af8c60a9572c707e7004c9a284dd6cd3306ce
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/configure.json | 6 | ||||
-rw-r--r-- | src/corelib/global/qconfig-bootstrapped.h | 1 | ||||
-rw-r--r-- | src/corelib/io/qtldurl.cpp | 6 | ||||
-rw-r--r-- | src/corelib/io/qtldurl_p.h | 2 | ||||
-rw-r--r-- | src/corelib/io/qurl.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qurl.h | 2 | ||||
-rw-r--r-- | src/network/access/qnetworkcookiejar.cpp | 11 |
7 files changed, 29 insertions, 1 deletions
diff --git a/src/corelib/configure.json b/src/corelib/configure.json index 238002c150..c1bd37fd0c 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -576,6 +576,12 @@ "purpose": "Provides support for command line parsing.", "section": "Utilities", "output": [ "publicFeature" ] + }, + "topleveldomain": { + "label": "QUrl::topLevelDomain()", + "description": "Provides support for extracting the top level domain from URLs.", + "section": "Utilities", + "output": [ "publicFeature" ] } }, diff --git a/src/corelib/global/qconfig-bootstrapped.h b/src/corelib/global/qconfig-bootstrapped.h index 76e4e98a74..3b86e94cdd 100644 --- a/src/corelib/global/qconfig-bootstrapped.h +++ b/src/corelib/global/qconfig-bootstrapped.h @@ -74,6 +74,7 @@ #define QT_NO_SYSTEMLOCALE #define QT_NO_THREAD #define QT_FEATURE_timezone -1 +#define QT_FEATURE_topleveldomain -1 #define QT_NO_TRANSLATION #define QT_FEATURE_translation -1 #define QT_NO_GEOM_VARIANT diff --git a/src/corelib/io/qtldurl.cpp b/src/corelib/io/qtldurl.cpp index dd0ee6068d..96543bbbfd 100644 --- a/src/corelib/io/qtldurl.cpp +++ b/src/corelib/io/qtldurl.cpp @@ -37,6 +37,10 @@ ** ****************************************************************************/ +#include <qglobal.h> + +#if QT_CONFIG(topleveldomain) + #include "qplatformdefs.h" #include "qurl.h" #include "private/qurltlds_p.h" @@ -125,3 +129,5 @@ Q_CORE_EXPORT bool qIsEffectiveTLD(const QStringRef &domain) } QT_END_NAMESPACE + +#endif diff --git a/src/corelib/io/qtldurl_p.h b/src/corelib/io/qtldurl_p.h index b9fbdebbc5..4636f18874 100644 --- a/src/corelib/io/qtldurl_p.h +++ b/src/corelib/io/qtldurl_p.h @@ -55,6 +55,8 @@ #include "QtCore/qurl.h" #include "QtCore/qstring.h" +QT_REQUIRE_CONFIG(topleveldomain); + QT_BEGIN_NAMESPACE Q_CORE_EXPORT QString qTopLevelDomain(const QString &domain); diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 42a742213b..c165aef5a2 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -3117,6 +3117,7 @@ bool QUrl::hasFragment() const return d->hasFragment(); } +#if QT_CONFIG(topleveldomain) /*! \since 4.8 @@ -3151,6 +3152,7 @@ QString QUrl::topLevelDomain(ComponentFormattingOptions options) const } return tld; } +#endif /*! Returns the result of the merge of this URL with \a relative. This diff --git a/src/corelib/io/qurl.h b/src/corelib/io/qurl.h index bce271fcb1..a554a3b07e 100644 --- a/src/corelib/io/qurl.h +++ b/src/corelib/io/qurl.h @@ -235,7 +235,9 @@ public: void setHost(const QString &host, ParsingMode mode = DecodedMode); QString host(ComponentFormattingOptions = FullyDecoded) const; +#if QT_CONFIG(topleveldomain) QString topLevelDomain(ComponentFormattingOptions options = FullyDecoded) const; +#endif void setPort(int port); int port(int defaultPort = -1) const; diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp index 429b71eb21..0540cb740f 100644 --- a/src/network/access/qnetworkcookiejar.cpp +++ b/src/network/access/qnetworkcookiejar.cpp @@ -335,11 +335,20 @@ bool QNetworkCookieJar::validateCookie(const QNetworkCookie &cookie, const QUrl if (!isParentDomain(domain, host) && !isParentDomain(host, domain)) return false; // not accepted + if (domain.startsWith(QLatin1Char('.'))) + domain = domain.mid(1); + +#if QT_CONFIG(topleveldomain) // the check for effective TLDs makes the "embedded dot" rule from RFC 2109 section 4.3.2 // redundant; the "leading dot" rule has been relaxed anyway, see QNetworkCookie::normalize() // we remove the leading dot for this check if it's present - if (qIsEffectiveTLD(domain.startsWith('.') ? domain.remove(0, 1) : domain)) + if (qIsEffectiveTLD(domain)) return false; // not accepted +#else + // provide minimal checking by not accepting cookies on real TLDs + if (!domain.contains(QLatin1Char('.'))) + return false; +#endif return true; } |