summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/network/access/qnetworkcookie.cpp16
-rw-r--r--tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp6
2 files changed, 18 insertions, 4 deletions
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp
index 55049280aa..664bc8282c 100644
--- a/src/network/access/qnetworkcookie.cpp
+++ b/src/network/access/qnetworkcookie.cpp
@@ -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
diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
index 25d91d63f5..bcfe9f090f 100644
--- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
+++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
@@ -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/");