Handle RemovePath correctly when calling matches()

Change-Id: Ied324a537df127e676fad26b42e658a9d5aeec9b
Reviewed-by: David Faure <david.faure@kdab.com>
bb10
Andy Shaw 2016-11-21 11:38:43 +01:00
parent 9f17c24589
commit 3cd457bdad
2 changed files with 53 additions and 0 deletions

View File

@ -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);

View File

@ -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"