summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2016-11-21 11:38:43 +0100
committerAndy Shaw <andy.shaw@qt.io>2016-11-22 07:05:30 +0000
commit3cd457bdad6eee4a703ef9773b80165a272fbdc7 (patch)
treec0112073c97b269e642a03653d408e19a65e0dec
parent9f17c245893e296d5c92ed1ef1e5d08896b469b1 (diff)
Handle RemovePath correctly when calling matches()
Change-Id: Ied324a537df127e676fad26b42e658a9d5aeec9b Reviewed-by: David Faure <david.faure@kdab.com>
-rw-r--r--src/corelib/io/qurl.cpp3
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp50
2 files changed, 53 insertions, 0 deletions
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 7512bcd83f..de78d09dd9 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -3703,6 +3703,9 @@ bool QUrl::matches(const QUrl &url, FormattingOptions options) const
if ((d->sectionIsPresent & mask) != (url.d->sectionIsPresent & mask))
return false;
+ if (options & QUrl::RemovePath)
+ return true;
+
// Compare paths, after applying path-related options
QString path1;
d->appendPath(path1, options, QUrlPrivate::Path);
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 8f99047df3..670b72acc8 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -182,6 +182,8 @@ private slots:
void streaming();
void detach();
void testThreading();
+ void matches_data();
+ void matches();
private:
void testThreadingHelper();
@@ -4023,6 +4025,54 @@ void tst_QUrl::testThreading()
delete s_urlStorage;
}
+void tst_QUrl::matches_data()
+{
+ QTest::addColumn<QString>("urlStrOne");
+ QTest::addColumn<QString>("urlStrTwo");
+ QTest::addColumn<uint>("options");
+ QTest::addColumn<bool>("matches");
+
+ QTest::newRow("matchingString-none") << "http://www.website.com/directory/?#ref"
+ << "http://www.website.com/directory/?#ref"
+ << uint(QUrl::None) << true;
+ QTest::newRow("nonMatchingString-none") << "http://www.website.com/directory/?#ref"
+ << "http://www.nomatch.com/directory/?#ref"
+ << uint(QUrl::None) << false;
+ QTest::newRow("matchingHost-removePath") << "http://www.website.com/directory"
+ << "http://www.website.com/differentdir"
+ << uint(QUrl::RemovePath) << true;
+ QTest::newRow("nonMatchingHost-removePath") << "http://www.website.com/directory"
+ << "http://www.different.com/differentdir"
+ << uint(QUrl::RemovePath) << false;
+ QTest::newRow("matchingHost-removePathAuthority") << "http://user:pass@www.website.com/directory"
+ << "http://www.website.com/differentdir"
+ << uint(QUrl::RemovePath | QUrl::RemoveAuthority)
+ << true;
+ QTest::newRow("nonMatchingHost-removePathAuthority") << "http://user:pass@www.website.com/directory"
+ << "http://user:pass@www.different.com/differentdir"
+ << uint(QUrl::RemovePath | QUrl::RemoveAuthority)
+ << true;
+ QTest::newRow("matchingHostAuthority-removePathAuthority")
+ << "http://user:pass@www.website.com/directory" << "http://www.website.com/differentdir"
+ << uint(QUrl::RemovePath | QUrl::RemoveAuthority) << true;
+ QTest::newRow("nonMatchingAuthority-removePathAuthority")
+ << "http://user:pass@www.website.com/directory"
+ << "http://otheruser:otherpass@www.website.com/directory"
+ << uint(QUrl::RemovePath | QUrl::RemoveAuthority) << true;
+}
+
+void tst_QUrl::matches()
+{
+ QFETCH(QString, urlStrOne);
+ QFETCH(QString, urlStrTwo);
+ QFETCH(uint, options);
+ QFETCH(bool, matches);
+
+ QUrl urlOne(urlStrOne);
+ QUrl urlTwo(urlStrTwo);
+ QCOMPARE(urlOne.matches(urlTwo, QUrl::FormattingOptions(options)), matches);
+}
+
QTEST_MAIN(tst_QUrl)
#include "tst_qurl.moc"