summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Hartmann <peter.hartmann@trolltech.com>2009-04-30 12:35:46 (GMT)
committerPeter Hartmann <peter.hartmann@trolltech.com>2009-04-30 14:44:17 (GMT)
commit1a18308b311f031d001e3b3e98ffb61e840a6d8c (patch)
treedb40b5f8d17c1eb3baf2932fd3148c5a6d172929
parentea80a3dc8acdb95c0c217b3574718c88c7a36e9f (diff)
downloadQt-1a18308b311f031d001e3b3e98ffb61e840a6d8c.zip
Qt-1a18308b311f031d001e3b3e98ffb61e840a6d8c.tar.gz
Qt-1a18308b311f031d001e3b3e98ffb61e840a6d8c.tar.bz2
QNetworkCookieJar: allow cookies with wrong domain attribute
According to the (old) cookie RFC 2109, the domain attribute must always contain a leading dot. Some servers do not have that, but all browsers accept those cookies anyway, so we should do that as well. Reviewed-by: Olivier Reviewed-by: Denis Task-number: 228974
-rw-r--r--src/network/access/qnetworkcookie.cpp9
-rw-r--r--tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp8
2 files changed, 8 insertions, 9 deletions
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp
index 01a743b..aaa5075 100644
--- a/src/network/access/qnetworkcookie.cpp
+++ b/src/network/access/qnetworkcookie.cpp
@@ -976,14 +976,14 @@ QList<QNetworkCookie> QNetworkCookie::parseCookies(const QByteArray &cookieStrin
cookie.setExpirationDate(dt);
} else if (field.first == "domain") {
QByteArray rawDomain = field.second;
- QString maybeLeadingDot;
if (rawDomain.startsWith('.')) {
- maybeLeadingDot = QLatin1Char('.');
rawDomain = rawDomain.mid(1);
}
-
QString normalizedDomain = QUrl::fromAce(QUrl::toAce(QString::fromUtf8(rawDomain)));
- cookie.setDomain(maybeLeadingDot + normalizedDomain);
+ // always add the dot, there are some servers that forget the
+ // leading dot. This is actually forbidden according to RFC 2109,
+ // but all browsers accept it anyway so we do that as well
+ cookie.setDomain(QLatin1Char('.') + normalizedDomain);
} else if (field.first == "max-age") {
bool ok = false;
int secs = field.second.toInt(&ok);
@@ -1184,7 +1184,6 @@ bool QNetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieLis
cookie.expirationDate() < now;
// validate the cookie & set the defaults if unset
- // (RFC 2965: "The request-URI MUST path-match the Path attribute of the cookie.")
if (cookie.path().isEmpty())
cookie.setPath(defaultPath);
else if (!isParentPath(pathAndFileName, cookie.path()))
diff --git a/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp b/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp
index 36a4b45..4ee5b9f 100644
--- a/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp
+++ b/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp
@@ -234,7 +234,7 @@ void tst_QNetworkCookie::parseSingleCookie_data()
QTest::newRow("path-with-utf8-2") << "a=b;path=/R%C3%A9sum%C3%A9" << cookie;
cookie.setPath(QString());
- cookie.setDomain("trolltech.com");
+ cookie.setDomain(".trolltech.com");
QTest::newRow("plain-domain1") << "a=b;domain=trolltech.com" << cookie;
QTest::newRow("plain-domain2") << "a=b; domain=trolltech.com " << cookie;
QTest::newRow("plain-domain3") << "a=b;domain=TROLLTECH.COM" << cookie;
@@ -246,7 +246,7 @@ void tst_QNetworkCookie::parseSingleCookie_data()
QTest::newRow("dot-domain3") << "a=b; domain=.TROLLTECH.COM" << cookie;
QTest::newRow("dot-domain4") << "a=b; Domain = .TROLLTECH.COM" << cookie;
- cookie.setDomain(QString::fromUtf8("d\303\270gn\303\245pent.troll.no"));
+ cookie.setDomain(QString::fromUtf8(".d\303\270gn\303\245pent.troll.no"));
QTest::newRow("idn-domain1") << "a=b;domain=xn--dgnpent-gxa2o.troll.no" << cookie;
QTest::newRow("idn-domain2") << "a=b;domain=d\303\270gn\303\245pent.troll.no" << cookie;
QTest::newRow("idn-domain3") << "a=b;domain=XN--DGNPENT-GXA2O.TROLL.NO" << cookie;
@@ -259,7 +259,7 @@ void tst_QNetworkCookie::parseSingleCookie_data()
QTest::newRow("dot-idn-domain3") << "a=b;domain=.XN--DGNPENT-GXA2O.TROLL.NO" << cookie;
QTest::newRow("dot-idn-domain4") << "a=b;domain=.D\303\230GN\303\205PENT.troll.NO" << cookie;
- cookie.setDomain("trolltech.com");
+ cookie.setDomain(".trolltech.com");
cookie.setPath("/");
QTest::newRow("two-fields") << "a=b;domain=trolltech.com;path=/" << cookie;
QTest::newRow("two-fields2") << "a=b; domain=trolltech.com; path=/" << cookie;
@@ -662,7 +662,7 @@ void tst_QNetworkCookie::parseMultipleCookies_data()
QTest::newRow("complex-1") << "c=d, a=, foo=bar; path=/" << list;
cookie.setName("baz");
- cookie.setDomain("trolltech.com");
+ cookie.setDomain(".trolltech.com");
list.prepend(cookie);
QTest::newRow("complex-2") << "baz=bar; path=/; domain=trolltech.com, c=d,a=,foo=bar; path=/" << list;