summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Hartmann <peter.hartmann@nokia.com>2011-04-27 09:48:53 (GMT)
committerQt Commercial Integration <QtCommercial@digia.com>2012-01-31 10:24:40 (GMT)
commit9d3e97d11b512157da26b51f2a29b80d698db5c7 (patch)
tree6e0fc192c0047dc1dce42286ff7cde8c94b8349c
parent36bebe1ec73bd4df96df5eddafebfd5da18b34e7 (diff)
downloadQt-9d3e97d11b512157da26b51f2a29b80d698db5c7.zip
Qt-9d3e97d11b512157da26b51f2a29b80d698db5c7.tar.gz
Qt-9d3e97d11b512157da26b51f2a29b80d698db5c7.tar.bz2
QNetworkCookie: allow spaces in unquoted values
We should follow http://tools.ietf.org/html/draft-ietf-httpstate-cookie-23 , which says parse the value until reaching the next ';' or the end of the line. Other cookie implementations allow spaces in unquoted values as well. Reviewed-by: Martin Petersson Task-number: QTBUG-18876
-rw-r--r--src/network/access/qnetworkcookie.cpp9
-rw-r--r--tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp8
2 files changed, 13 insertions, 4 deletions
diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp
index 983c6ee..98487f9 100644
--- a/src/network/access/qnetworkcookie.cpp
+++ b/src/network/access/qnetworkcookie.cpp
@@ -395,8 +395,8 @@ static QPair<QByteArray, QByteArray> nextField(const QByteArray &text, int &posi
// qdtext = <any TEXT except <">>
// quoted-pair = "\" CHAR
- // If its NAME=VALUE, retain the value as is
- // refer to ttp://bugreports.qt.nokia.com/browse/QTBUG-17746
+ // If it is NAME=VALUE, retain the value as is
+ // refer to http://bugreports.qt.nokia.com/browse/QTBUG-17746
if (isNameValue)
second += '"';
++i;
@@ -432,7 +432,9 @@ static QPair<QByteArray, QByteArray> nextField(const QByteArray &text, int &posi
position = i;
for ( ; i < length; ++i) {
register char c = text.at(i);
- if (c == ',' || c == ';' || isLWS(c))
+ // for name value pairs, we want to parse until reaching the next ';'
+ // and not break when reaching a space char
+ if (c == ',' || c == ';' || ((isNameValue && (c == '\n' || c == '\r')) || (!isNameValue && isLWS(c))))
break;
}
@@ -487,7 +489,6 @@ QByteArray QNetworkCookie::toRawForm(RawForm form) const
result += '=';
if ((d->value.contains(';') ||
d->value.contains(',') ||
- d->value.contains(' ') ||
d->value.contains('"')) &&
(!d->value.startsWith('"') &&
!d->value.endsWith('"'))) {
diff --git a/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp b/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp
index 0071a24..68ca039 100644
--- a/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp
+++ b/tests/auto/qnetworkcookie/tst_qnetworkcookie.cpp
@@ -182,6 +182,14 @@ void tst_QNetworkCookie::parseSingleCookie_data()
cookie.setValue("\"\\\"a, b; c\\\"\"");
QTest::newRow("with-value-with-special5") << "a = \"\\\"a, b; c\\\"\"" << cookie;
+ cookie.setValue("b c");
+ QTest::newRow("with-value-with-whitespace") << "a = b c" << cookie;
+
+ cookie.setValue("\"b\"");
+ QTest::newRow("quoted-value") << "a = \"b\"" << cookie;
+ cookie.setValue("\"b c\"");
+ QTest::newRow("quoted-value-with-whitespace") << "a = \"b c\"" << cookie;
+
cookie.setValue("b");
cookie.setSecure(true);
QTest::newRow("secure") << "a=b;secure" << cookie;