From 19bfcdaa43f6ac8841942cb545811eab409f1713 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 21 Apr 2020 14:27:02 +0200 Subject: [PATCH] Port qIsEffectiveTLD() to QStringView MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add a piece of documentation that the input needs to be in lower-case (the implementation uses qt_hash to index into a table of TLDs, and qt_hash is case-sensitive). Change-Id: I911c0e2bb0826fc1b0fc01ed60bdfd6e4c0298f2 Reviewed-by: MÃ¥rten Nordheim --- src/network/access/qnetworkcookiejar.cpp | 2 +- src/network/kernel/qtldurl.cpp | 6 ++++-- src/network/kernel/qtldurl_p.h | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp index af5b126953d..0856dd2252e 100644 --- a/src/network/access/qnetworkcookiejar.cpp +++ b/src/network/access/qnetworkcookiejar.cpp @@ -47,7 +47,7 @@ #include "private/qtldurl_p.h" #else QT_BEGIN_NAMESPACE -static bool qIsEffectiveTLD(QString domain) +static bool qIsEffectiveTLD(QStringView domain) { // provide minimal checking by not accepting cookies on real TLDs return !domain.contains(QLatin1Char('.')); diff --git a/src/network/kernel/qtldurl.cpp b/src/network/kernel/qtldurl.cpp index c2f7d1de26e..d93407d6f5b 100644 --- a/src/network/kernel/qtldurl.cpp +++ b/src/network/kernel/qtldurl.cpp @@ -114,9 +114,11 @@ Q_NETWORK_EXPORT QString qTopLevelDomain(const QString &domain) \internal Return true if \a domain is a top-level-domain per Qt's copy of the Mozilla public suffix list. + + The \a domain must be in lower-case format (as per QString::toLower()). */ -Q_NETWORK_EXPORT bool qIsEffectiveTLD(const QStringRef &domain) +Q_NETWORK_EXPORT bool qIsEffectiveTLD(QStringView domain) { // for domain 'foo.bar.com': // 1. return if TLD table contains 'foo.bar.com' @@ -126,7 +128,7 @@ Q_NETWORK_EXPORT bool qIsEffectiveTLD(const QStringRef &domain) if (containsTLDEntry(domain, ExactMatch)) // 1 return true; - const int dot = domain.indexOf(QLatin1Char('.')); + const auto dot = domain.indexOf(QLatin1Char('.')); if (dot < 0) // Actual TLD: may be effective if the subject of a wildcard rule: return containsTLDEntry(QString(QLatin1Char('.') + domain), SuffixMatch); if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2 diff --git a/src/network/kernel/qtldurl_p.h b/src/network/kernel/qtldurl_p.h index a6948cfd488..c0a07d8e008 100644 --- a/src/network/kernel/qtldurl_p.h +++ b/src/network/kernel/qtldurl_p.h @@ -60,10 +60,10 @@ QT_REQUIRE_CONFIG(topleveldomain); QT_BEGIN_NAMESPACE Q_NETWORK_EXPORT QString qTopLevelDomain(const QString &domain); -Q_NETWORK_EXPORT bool qIsEffectiveTLD(const QStringRef &domain); +Q_NETWORK_EXPORT bool qIsEffectiveTLD(QStringView domain); inline bool qIsEffectiveTLD(const QString &domain) { - return qIsEffectiveTLD(QStringRef(&domain)); + return qIsEffectiveTLD(qToStringViewIgnoringNull(domain)); } QT_END_NAMESPACE