Fix parsing of empty port sections in URLs
The RFC does allow it. It even has examples showing them as valid. In
section 6.2.3, it shows:
http://example.com
http://example.com/
http://example.com:/
http://example.com:80/
Change-Id: Id75834dab9ed466e94c7ffff1444b7195ad21cab
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@theqtcompany.com>
bb10
parent
5b37c9f7d3
commit
7ab0829823
|
|
@ -1046,7 +1046,7 @@ inline void QUrlPrivate::setAuthority(const QString &auth, int from, int end, QU
|
|||
|
||||
if (colonIndex == end - 1) {
|
||||
// found a colon but no digits after it
|
||||
setError(PortEmptyError, auth, colonIndex + 1);
|
||||
port = -1;
|
||||
} else if (uint(colonIndex) < uint(end)) {
|
||||
unsigned long x = 0;
|
||||
for (int i = colonIndex + 1; i < end; ++i) {
|
||||
|
|
|
|||
|
|
@ -148,6 +148,8 @@ private slots:
|
|||
void hostFlags_data();
|
||||
void hostFlags();
|
||||
void setPort();
|
||||
void port_data();
|
||||
void port();
|
||||
void toEncoded_data();
|
||||
void toEncoded();
|
||||
void setAuthority_data();
|
||||
|
|
@ -2205,8 +2207,6 @@ void tst_QUrl::strictParser_data()
|
|||
// FIXME: add some tests for prohibited BiDi (RFC 3454 section 6)
|
||||
|
||||
// port errors happen in TolerantMode too
|
||||
QTest::newRow("empty-port-1") << "http://example.com:" << "Port field was empty";
|
||||
QTest::newRow("empty-port-2") << "http://example.com:/" << "Port field was empty";
|
||||
QTest::newRow("invalid-port-1") << "http://example.com:-1" << "Invalid port";
|
||||
QTest::newRow("invalid-port-2") << "http://example.com:abc" << "Invalid port";
|
||||
QTest::newRow("invalid-port-3") << "http://example.com:9a" << "Invalid port";
|
||||
|
|
@ -2783,6 +2783,31 @@ void tst_QUrl::setPort()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QUrl::port_data()
|
||||
{
|
||||
QTest::addColumn<QString>("input");
|
||||
QTest::addColumn<int>("port");
|
||||
|
||||
QTest::newRow("no-port-1") << "http://example.com" << -1;
|
||||
QTest::newRow("no-port-2") << "http://example.com/" << -1;
|
||||
QTest::newRow("empty-port-1") << "http://example.com:" << -1;
|
||||
QTest::newRow("empty-port-2") << "http://example.com:/" << -1;
|
||||
QTest::newRow("zero-port-1") << "http://example.com:0" << 0;
|
||||
QTest::newRow("zero-port-2") << "http://example.com:0/" << 0;
|
||||
QTest::newRow("set-port-1") << "http://example.com:80" << 80;
|
||||
QTest::newRow("set-port-2") << "http://example.com:80/" << 80;
|
||||
}
|
||||
|
||||
void tst_QUrl::port()
|
||||
{
|
||||
QFETCH(QString, input);
|
||||
QFETCH(int, port);
|
||||
|
||||
QUrl url(input);
|
||||
QVERIFY(url.isValid());
|
||||
QCOMPARE(url.port(), port);
|
||||
}
|
||||
|
||||
void tst_QUrl::toEncoded_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("url");
|
||||
|
|
|
|||
Loading…
Reference in New Issue