QNetworkCookie: allow cookies for IPv6 domains

For IPv6 addresses don't call toAce as it returns the empty string.
We should reflect the behavior of browsers here, which all accept
cookies from IPv6 addresses.

Original-patch-by: David Tapuska <dtapuska@blackberry.com>

Task-number: QTBUG-35022

Change-Id: Ic00369e923d044ec459822b2405865c13e4185b6
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
Peter Hartmann 2013-11-26 13:58:47 -05:00 committed by The Qt Project
parent 746dddeb9f
commit ae293c1cb2
2 changed files with 18 additions and 4 deletions

View File

@ -467,12 +467,19 @@ QByteArray QNetworkCookie::toRawForm(RawForm form) const
}
if (!d->domain.isEmpty()) {
result += "; domain=";
QString domainNoDot = d->domain;
if (domainNoDot.startsWith(QLatin1Char('.'))) {
if (d->domain.startsWith(QLatin1Char('.'))) {
result += '.';
domainNoDot = domainNoDot.mid(1);
result += QUrl::toAce(d->domain.mid(1));
} else {
QHostAddress hostAddr(d->domain);
if (hostAddr.protocol() == QAbstractSocket::IPv6Protocol) {
result += '[';
result += d->domain.toUtf8();
result += ']';
} else {
result += QUrl::toAce(d->domain);
}
}
result += QUrl::toAce(domainNoDot);
}
if (!d->path.isEmpty()) {
result += "; path=";
@ -1021,6 +1028,7 @@ void QNetworkCookie::normalize(const QUrl &url)
} else {
QHostAddress hostAddress(d->domain);
if (hostAddress.protocol() != QAbstractSocket::IPv4Protocol
&& hostAddress.protocol() != QAbstractSocket::IPv6Protocol
&& !d->domain.startsWith(QLatin1Char('.'))) {
// Ensure the domain starts with a dot if its field was not empty
// in the HTTP header. There are some servers that forget the

View File

@ -217,6 +217,12 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data()
result += cookie;
QTest::newRow("IPv4-address-as-domain") << preset << cookie << "http://127.0.0.1/" << result << true;
result.clear();
preset.clear();
cookie.setDomain("fe80::250:56ff:fec0:1");
result += cookie;
QTest::newRow("IPv6-address-as-domain") << preset << cookie << "http://[fe80::250:56ff:fec0:1]/" << result << true;
// setting the defaults:
finalCookie = cookie;
finalCookie.setPath("/something/");