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
This commit is contained in:
parent
8e9aa019bb
commit
863de43dca
@ -395,8 +395,8 @@ static QPair<QByteArray, QByteArray> nextField(const QByteArray &text, int &posi
|
|||||||
// qdtext = <any TEXT except <">>
|
// qdtext = <any TEXT except <">>
|
||||||
// quoted-pair = "\" CHAR
|
// quoted-pair = "\" CHAR
|
||||||
|
|
||||||
// If its NAME=VALUE, retain the value as is
|
// If it is NAME=VALUE, retain the value as is
|
||||||
// refer to ttp://bugreports.qt.nokia.com/browse/QTBUG-17746
|
// refer to http://bugreports.qt.nokia.com/browse/QTBUG-17746
|
||||||
if (isNameValue)
|
if (isNameValue)
|
||||||
second += '"';
|
second += '"';
|
||||||
++i;
|
++i;
|
||||||
@ -432,7 +432,9 @@ static QPair<QByteArray, QByteArray> nextField(const QByteArray &text, int &posi
|
|||||||
position = i;
|
position = i;
|
||||||
for ( ; i < length; ++i) {
|
for ( ; i < length; ++i) {
|
||||||
register char c = text.at(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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +489,6 @@ QByteArray QNetworkCookie::toRawForm(RawForm form) const
|
|||||||
result += '=';
|
result += '=';
|
||||||
if ((d->value.contains(';') ||
|
if ((d->value.contains(';') ||
|
||||||
d->value.contains(',') ||
|
d->value.contains(',') ||
|
||||||
d->value.contains(' ') ||
|
|
||||||
d->value.contains('"')) &&
|
d->value.contains('"')) &&
|
||||||
(!d->value.startsWith('"') &&
|
(!d->value.startsWith('"') &&
|
||||||
!d->value.endsWith('"'))) {
|
!d->value.endsWith('"'))) {
|
||||||
|
@ -182,6 +182,14 @@ void tst_QNetworkCookie::parseSingleCookie_data()
|
|||||||
cookie.setValue("\"\\\"a, b; c\\\"\"");
|
cookie.setValue("\"\\\"a, b; c\\\"\"");
|
||||||
QTest::newRow("with-value-with-special5") << "a = \"\\\"a, b; c\\\"\"" << cookie;
|
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.setValue("b");
|
||||||
cookie.setSecure(true);
|
cookie.setSecure(true);
|
||||||
QTest::newRow("secure") << "a=b;secure" << cookie;
|
QTest::newRow("secure") << "a=b;secure" << cookie;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user