QUrl: using sectionIsPresent in operator== broke for local files.
authorDavid Faure <faure@kde.org>
Mon, 14 May 2012 15:17:11 +0000 (17:17 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 14 May 2012 15:36:57 +0000 (17:36 +0200)
QUrl::fromLocalFile("/foo") doesn't set Host, but QUrl("file:///foo")
does (to remember that it saw a Host section, even if empty, which is
useful for urls like "remote://"). So ignore the Host flag in operator==.

Change-Id: I4322b4a75420c4e42766c0d65c1b121f28028a76
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/io/qurl.cpp
tests/auto/corelib/io/qurl/tst_qurl.cpp

index 07024d3..68523cd 100644 (file)
@@ -2382,7 +2382,11 @@ bool QUrl::operator ==(const QUrl &url) const
         return url.d->isEmpty();
     if (!url.d)
         return d->isEmpty();
-    return d->sectionIsPresent == url.d->sectionIsPresent &&
+
+    // Compare which sections are present, but ignore Host
+    // which is set by parsing but not by construction, when empty.
+    const int mask = QUrlPrivate::FullUrl & ~QUrlPrivate::Host;
+    return (d->sectionIsPresent & mask) == (url.d->sectionIsPresent & mask) &&
             d->scheme == url.d->scheme &&
             d->userName == url.d->userName &&
             d->password == url.d->password &&
index 48ff34a..1f3dcae 100644 (file)
@@ -309,6 +309,8 @@ void tst_QUrl::comparison2_data()
     QTest::newRow("samescheme") << QUrl("x:") << QUrl("x:") << 0;
     QTest::newRow("no-fragment-empty-fragment") << QUrl("http://kde.org/dir/") << QUrl("http://kde.org/dir/#") << -1;
     QTest::newRow("no-query-empty-query") << QUrl("http://kde.org/dir/") << QUrl("http://kde.org/dir/?") << -1;
+    QTest::newRow("simple-file-url") << QUrl("file:///home/dfaure/file") << QUrl("file:///home/dfaure/file") << 0;
+    QTest::newRow("fromLocalFile-vs-ctor") << QUrl::fromLocalFile("/home/dfaure/file") << QUrl("file:///home/dfaure/file") << 0;
 
     // the following three are by choice
     // the order could be the opposite and it would still be correct
@@ -2638,6 +2640,8 @@ void tst_QUrl::emptyAuthorityRemovesExistingAuthority()
 
 void tst_QUrl::acceptEmptyAuthoritySegments()
 {
+    QCOMPARE(QUrl("remote://").toString(), QString::fromLatin1("remote://"));
+
     // Verify that foo:///bar is not mangled to foo:/bar
     QString foo_triple_bar("foo:///bar"), foo_uni_bar("foo:/bar");