diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-01-15 14:49:32 -0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-17 18:13:42 +0100 |
commit | 83b1eaad44862828b3248840c33f16e0b73df479 (patch) | |
tree | fc613c93c1ea24e5c4fb477a98f6c1abd14721a1 /tests/auto/corelib/io/qurl/tst_qurl.cpp | |
parent | ba56beaea41620647c15a9f6b79cd7756c46698a (diff) |
Make a URL with absent authority be different from one with an empty one
This partially reverts 5764f5e6eaf149116a818658883cf4fae9830f30 and
fixes the problem differently.
After this commit, "file:///foo" is still equal to "file:/foo", but
"foo:///foo" becomes different from "foo:/foo", as it should be.
Task-number: QTBUG-36151
Change-Id: Ia38638b0f30a7dcf110aa89aa427254c007fc107
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests/auto/corelib/io/qurl/tst_qurl.cpp')
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 12b9159bf2..92dbb96817 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -169,6 +169,7 @@ private slots: void fileName(); void isEmptyForEncodedUrl(); void toEncodedNotUsingUninitializedPath(); + void emptyAuthorityRemovesExistingAuthority_data(); void emptyAuthorityRemovesExistingAuthority(); void acceptEmptyAuthoritySegments(); void lowercasesScheme(); @@ -3033,31 +3034,56 @@ void tst_QUrl::resolvedWithAbsoluteSchemes_data() const << QUrl::fromEncoded("http://andreas:hemmelig@www.vg.no/?my=query&your=query#yougotfragged"); } +void tst_QUrl::emptyAuthorityRemovesExistingAuthority_data() +{ + QTest::addColumn<QString>("input"); + QTest::addColumn<QString>("expected"); + QTest::newRow("regular") << "foo://example.com/something" << "foo:/something"; + QTest::newRow("empty") << "foo:///something" << "foo:/something"; +} + void tst_QUrl::emptyAuthorityRemovesExistingAuthority() { - QUrl url("http://example.com/something"); + QFETCH(QString, input); + QFETCH(QString, expected); + QUrl url(input); + QUrl orig = url; + url.setAuthority(QString()); QCOMPARE(url.authority(), QString()); + QVERIFY(url != orig); + QCOMPARE(url.toString(), expected); + QCOMPARE(url, QUrl(expected)); } void tst_QUrl::acceptEmptyAuthoritySegments() { QCOMPARE(QUrl("remote://").toString(), QString::fromLatin1("remote://")); - // Verify that foo:///bar is not mangled to foo:/bar + // Verify that foo:///bar is not mangled to foo:/bar nor vice-versa QString foo_triple_bar("foo:///bar"), foo_uni_bar("foo:/bar"); - QCOMPARE(foo_triple_bar, QUrl(foo_triple_bar).toString()); - QCOMPARE(foo_triple_bar, QString::fromUtf8(QUrl(foo_triple_bar).toEncoded())); + QVERIFY(QUrl(foo_triple_bar) != QUrl(foo_uni_bar)); + + QCOMPARE(QUrl(foo_triple_bar).toString(), foo_triple_bar); + QCOMPARE(QUrl(foo_triple_bar).toEncoded(), foo_triple_bar.toLatin1()); + + QCOMPARE(QUrl(foo_uni_bar).toString(), foo_uni_bar); + QCOMPARE(QUrl(foo_uni_bar).toEncoded(), foo_uni_bar.toLatin1()); + + QCOMPARE(QUrl(foo_triple_bar, QUrl::StrictMode).toString(), foo_triple_bar); + QCOMPARE(QUrl(foo_triple_bar, QUrl::StrictMode).toEncoded(), foo_triple_bar.toLatin1()); + + QCOMPARE(QUrl(foo_uni_bar, QUrl::StrictMode).toString(), foo_uni_bar); + QCOMPARE(QUrl(foo_uni_bar, QUrl::StrictMode).toEncoded(), foo_uni_bar.toLatin1()); - QCOMPARE(foo_uni_bar, QUrl(foo_uni_bar).toString()); - QCOMPARE(foo_uni_bar, QString::fromUtf8(QUrl(foo_uni_bar).toEncoded())); + // However, file:/bar is the same as file:///bar + QString file_triple_bar("file:///bar"), file_uni_bar("file:/bar"); - QCOMPARE(foo_triple_bar, QUrl(foo_triple_bar, QUrl::StrictMode).toString()); - QCOMPARE(foo_triple_bar, QString::fromUtf8(QUrl(foo_triple_bar, QUrl::StrictMode).toEncoded())); + QVERIFY(QUrl(file_triple_bar) == QUrl(file_uni_bar)); - QCOMPARE(foo_uni_bar, QUrl(foo_uni_bar, QUrl::StrictMode).toString()); - QCOMPARE(foo_uni_bar, QString::fromUtf8(QUrl(foo_uni_bar, QUrl::StrictMode).toEncoded())); + QCOMPARE(QUrl(file_uni_bar).toString(), file_triple_bar); + QCOMPARE(QUrl(file_uni_bar, QUrl::StrictMode).toString(), file_triple_bar); } void tst_QUrl::effectiveTLDs_data() @@ -3434,6 +3460,12 @@ void tst_QUrl::setComponents_data() QTest::newRow("host-empty") << QUrl("foo://example.com/path") << int(Host) << "" << Tolerant << true << PrettyDecoded << QString() << "foo:///path"; + QTest::newRow("authority-null") << QUrl("foo://example.com/path") + << int(Authority) << QString() << Tolerant << true + << PrettyDecoded << QString() << "foo:/path"; + QTest::newRow("authority-empty") << QUrl("foo://example.com/path") + << int(Authority) << "" << Tolerant << true + << PrettyDecoded << QString() << "foo:///path"; QTest::newRow("query-null") << QUrl("http://example.com/?q=foo") << int(Query) << QString() << Tolerant << true << PrettyDecoded << QString() << "http://example.com/"; |