Fix mis-handling of actual TLD in qIsEffectiveTLD()

If the domain passed down is an actual TLD that's the subject of a *
rule, e.g. "ck" subject to *.ck, then we were finding no dot in it and
concluding that it couldn't be the subject of a * rule.

Added a test for the specific .ck case and commented on where we could
get some canonical test data that I tripped over while researching
this. Cross-reference the cookie-jar test from the QUrl test, too.

Fixes: QTBUG-78097
Change-Id: Id858a9dae22e6b306a68df3fc199e0160f537159
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Edward Welbourne 2019-09-10 16:39:43 +02:00
parent da3c2cc6a8
commit 6cee284001
3 changed files with 15 additions and 4 deletions

View File

@ -125,10 +125,10 @@ Q_CORE_EXPORT bool qIsEffectiveTLD(const QStringRef &domain)
return true;
const int dot = domain.indexOf(QLatin1Char('.'));
if (dot >= 0) {
if (containsTLDEntry(domain.mid(dot), SuffixMatch)) // 2
return !containsTLDEntry(domain, ExceptionMatch); // 3
}
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
return !containsTLDEntry(domain, ExceptionMatch); // 3
return false;
}

View File

@ -3389,8 +3389,15 @@ void tst_QUrl::acceptEmptyAuthoritySegments()
void tst_QUrl::effectiveTLDs_data()
{
// See also: tst_QNetworkCookieJar::setCookiesFromUrl().
// in tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
QTest::addColumn<QUrl>("domain");
QTest::addColumn<QString>("TLD");
// TODO: autogenerate test-cases from:
// https://raw.githubusercontent.com/publicsuffix/list/master/tests/test_psl.txt
// checkPublicSuffix(domain, tail) appears in the list if
// either tail is null and domain is public or
// tail is the "registrable" part of domain; i.e. its minimal non-public tail.
QTest::newRow("yes0") << QUrl::fromEncoded("http://test.co.uk") << ".co.uk";
QTest::newRow("yes1") << QUrl::fromEncoded("http://test.com") << ".com";

View File

@ -166,6 +166,10 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data()
// 2. anything .ck is an effective TLD ('*.ck'), but 'www.ck' is an exception
result.clear();
preset.clear();
cookie.setDomain(".ck");
QTest::newRow("effective-tld.ck-denied") << preset << cookie << "http://foo.ck" << result << false;
result.clear();
preset.clear();
cookie.setDomain(".foo.ck");
result += cookie;
QTest::newRow("effective-tld2-accepted2") << preset << cookie << "http://foo.ck" << result << true;