From 21666e3857cc9d4c93c6179490c1df46a795de53 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Fri, 14 Dec 2012 19:55:36 +0100 Subject: QUrl: make sure setAuthority is consistent with setHost ... which is important for an empty but non-null authority. In Qt5 this is already working. Change-Id: I7d389037f71320c6f06897b220633311c3611eea Reviewed-by: Thiago Macieira --- src/corelib/io/qurl.cpp | 5 ++++- tests/auto/qurl/tst_qurl.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 9bb411d..8aaf0e0 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -3574,7 +3574,10 @@ void QUrlPrivate::setAuthority(const QString &auth) isHostValid = true; if (auth.isEmpty()) { setUserInfo(QString()); - host.clear(); + if (auth.isNull()) + host.clear(); + else + host = QLatin1String(""); port = -1; return; } diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 81f646d..bccd532 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -189,6 +189,8 @@ private slots: void toEncoded(); void setAuthority_data(); void setAuthority(); + void setEmptyAuthority_data(); + void setEmptyAuthority(); void errorString(); void clear(); void resolvedWithAbsoluteSchemes() const; @@ -3776,6 +3778,28 @@ void tst_QUrl::setAuthority() QCOMPARE(u.toString(), url); } +void tst_QUrl::setEmptyAuthority_data() +{ + QTest::addColumn("host"); + QTest::addColumn("authority"); + QTest::addColumn("expectedUrlString"); + + QTest::newRow("null host and authority") << QString() << QString() << QString(""); + QTest::newRow("empty host and authority") << QString("") << QString("") << QString("//"); +} + +void tst_QUrl::setEmptyAuthority() +{ + QFETCH(QString, host); + QFETCH(QString, authority); + QFETCH(QString, expectedUrlString); + QUrl u; + u.setHost(host); + QCOMPARE(u.toString(), expectedUrlString); + u.setAuthority(authority); + QCOMPARE(u.toString(), expectedUrlString); +} + void tst_QUrl::errorString() { QUrl u = QUrl::fromEncoded("http://strange@bad_hostname/", QUrl::StrictMode); -- cgit v0.12