QNetworkCookieJar: reduce #if-#else branching

Add a definition for qIsEffectiveTLD for when Qt is configured with
-no-feature-topleveldomain. Then we can merge the #if-#else branch.

Change-Id: I91bc329ab95744a2e10dcc4168cd8b84f8fee9f6
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
bb10
Mårten Nordheim 2018-04-27 17:08:51 +02:00
parent 8a1baaf336
commit dcf476503e
1 changed files with 11 additions and 10 deletions

View File

@ -45,6 +45,14 @@
#include "QtCore/qdatetime.h"
#if QT_CONFIG(topleveldomain)
#include "private/qtldurl_p.h"
#else
QT_BEGIN_NAMESPACE
static bool qIsEffectiveTLD(QString domain)
{
// provide minimal checking by not accepting cookies on real TLDs
return !domain.contains(QLatin1Char('.'));
}
QT_END_NAMESPACE
#endif
QT_BEGIN_NAMESPACE
@ -356,19 +364,12 @@ bool QNetworkCookieJar::validateCookie(const QNetworkCookie &cookie, const QUrl
// https://tools.ietf.org/html/rfc6265#section-5.3 step 5
if (host == domain)
return true;
#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))
return false; // not accepted
#else
// provide minimal checking by not accepting cookies on real TLDs
if (!domain.contains(QLatin1Char('.')))
return false;
#endif
return true;
// Normally defined in qtldurl_p.h, but uses fall-back in this file when topleveldomain isn't
// configured:
return !qIsEffectiveTLD(domain);
}
QT_END_NAMESPACE