QUrl: a url with a fragment or query, and one without, are different.
authorDavid Faure <faure@kde.org>
Mon, 14 May 2012 12:48:23 +0000 (14:48 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 14 May 2012 15:36:50 +0000 (17:36 +0200)
Fix operator== and operator< so that a URL with an empty fragment
or query, is not treated as equal to a URL without any fragment or query.
This restores the Qt4 behavior on this particular issue.

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

index 3e711b1..07024d3 100644 (file)
@@ -2356,10 +2356,16 @@ bool QUrl::operator <(const QUrl &url) const
     if (cmp != 0)
         return cmp < 0;
 
+    if (d->hasQuery() != url.d->hasQuery())
+        return url.d->hasQuery();
+
     cmp = d->query.compare(url.d->query);
     if (cmp != 0)
         return cmp < 0;
 
+    if (d->hasFragment() != url.d->hasFragment())
+        return url.d->hasFragment();
+
     cmp = d->fragment.compare(url.d->fragment);
     return cmp < 0;
 }
@@ -2376,7 +2382,8 @@ bool QUrl::operator ==(const QUrl &url) const
         return url.d->isEmpty();
     if (!url.d)
         return d->isEmpty();
-    return d->scheme == url.d->scheme &&
+    return d->sectionIsPresent == url.d->sectionIsPresent &&
+            d->scheme == url.d->scheme &&
             d->userName == url.d->userName &&
             d->password == url.d->password &&
             d->host == url.d->host &&
index 38b9dc3..48ff34a 100644 (file)
@@ -307,6 +307,8 @@ void tst_QUrl::comparison2_data()
 
     QTest::newRow("scheme-null") << QUrl("x:") << QUrl() << 1;
     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;
 
     // the following three are by choice
     // the order could be the opposite and it would still be correct