QNetworkCookie: allow cookies for IPv4 domains
If the domain is an IP address, we should not do any magic regarding leading dots etc. Task-number: QTBUG-35022 Change-Id: I7722de4e6027666dde27e9e37b6353e3da775d94 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
parent
18a36fd6ec
commit
746dddeb9f
@ -51,6 +51,7 @@
|
|||||||
#include "QtCore/qstring.h"
|
#include "QtCore/qstring.h"
|
||||||
#include "QtCore/qstringlist.h"
|
#include "QtCore/qstringlist.h"
|
||||||
#include "QtCore/qurl.h"
|
#include "QtCore/qurl.h"
|
||||||
|
#include "QtNetwork/qhostaddress.h"
|
||||||
#include "private/qobject_p.h"
|
#include "private/qobject_p.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
@ -1015,15 +1016,20 @@ void QNetworkCookie::normalize(const QUrl &url)
|
|||||||
d->path = defaultPath;
|
d->path = defaultPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->domain.isEmpty())
|
if (d->domain.isEmpty()) {
|
||||||
d->domain = url.host();
|
d->domain = url.host();
|
||||||
else if (!d->domain.startsWith(QLatin1Char('.')))
|
} else {
|
||||||
|
QHostAddress hostAddress(d->domain);
|
||||||
|
if (hostAddress.protocol() != QAbstractSocket::IPv4Protocol
|
||||||
|
&& !d->domain.startsWith(QLatin1Char('.'))) {
|
||||||
// Ensure the domain starts with a dot if its field was not empty
|
// Ensure the domain starts with a dot if its field was not empty
|
||||||
// in the HTTP header. There are some servers that forget the
|
// in the HTTP header. There are some servers that forget the
|
||||||
// leading dot and this is actually forbidden according to RFC 2109,
|
// leading dot and this is actually forbidden according to RFC 2109,
|
||||||
// but all browsers accept it anyway so we do that as well.
|
// but all browsers accept it anyway so we do that as well.
|
||||||
d->domain.prepend(QLatin1Char('.'));
|
d->domain.prepend(QLatin1Char('.'));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef QT_NO_DEBUG_STREAM
|
#ifndef QT_NO_DEBUG_STREAM
|
||||||
QDebug operator<<(QDebug s, const QNetworkCookie &cookie)
|
QDebug operator<<(QDebug s, const QNetworkCookie &cookie)
|
||||||
|
@ -211,6 +211,11 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data()
|
|||||||
result += cookie;
|
result += cookie;
|
||||||
QTest::newRow("effective-tld2-accepted") << preset << cookie << "http://www.gobiernoelectronico.ar" << result << true;
|
QTest::newRow("effective-tld2-accepted") << preset << cookie << "http://www.gobiernoelectronico.ar" << result << true;
|
||||||
|
|
||||||
|
result.clear();
|
||||||
|
preset.clear();
|
||||||
|
cookie.setDomain("127.0.0.1");
|
||||||
|
result += cookie;
|
||||||
|
QTest::newRow("IPv4-address-as-domain") << preset << cookie << "http://127.0.0.1/" << result << true;
|
||||||
|
|
||||||
// setting the defaults:
|
// setting the defaults:
|
||||||
finalCookie = cookie;
|
finalCookie = cookie;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user