From 7ab0829823024dd07d15ff6786e3648388d4f28d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 12 Apr 2016 13:38:18 -0700 Subject: 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 Reviewed-by: Edward Welbourne Reviewed-by: Timur Pocheptsov --- tests/auto/corelib/io/qurl/tst_qurl.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'tests/auto/corelib/io/qurl/tst_qurl.cpp') diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index b284e5fc9c..eba058a13c 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -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("input"); + QTest::addColumn("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("url"); -- cgit v1.2.3