QUrlQuery: fix operator== for emptied object case

If an object had elements and then was emptied, it will have a non-null
d pointer, which wasn't taken into account in the comparison.

Fixes: QTBUG-109840
Pick-to: 6.5 6.4 6.2
Change-Id: I69ecc04064514f939896fffd17376aa18184653c
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Thiago Macieira 2023-01-05 09:50:28 -03:00
parent d298ec3a6f
commit 3d584b1093
2 changed files with 11 additions and 1 deletions

View File

@ -401,7 +401,11 @@ bool QUrlQuery::operator ==(const QUrlQuery &other) const
return d->valueDelimiter == other.d->valueDelimiter &&
d->pairDelimiter == other.d->pairDelimiter &&
d->itemList == other.d->itemList;
return false;
const QUrlQueryPrivate *x = d ? d.data() : other.d.data();
return x->valueDelimiter == defaultQueryValueDelimiter() &&
x->pairDelimiter == defaultQueryPairDelimiter() &&
x->itemList.isEmpty();
}
/*!

View File

@ -210,12 +210,14 @@ void tst_QUrlQuery::constructing()
void tst_QUrlQuery::addRemove()
{
QUrlQuery query;
QCOMPARE(query, query);
{
// one item
query.addQueryItem("a", "b");
QVERIFY(!query.isEmpty());
QVERIFY(query.hasQueryItem("a"));
QCOMPARE_NE(query, QUrlQuery());
QCOMPARE(query.queryItemValue("a"), QString("b"));
QCOMPARE(query.allQueryItemValues("a"), QStringList() << "b");
@ -226,6 +228,7 @@ void tst_QUrlQuery::addRemove()
}
QUrlQuery original = query;
QCOMPARE(query, original);
{
// two items
@ -298,6 +301,9 @@ void tst_QUrlQuery::addRemove()
query.removeQueryItem("a");
query.removeQueryItem("e");
QVERIFY(query.isEmpty());
QVERIFY(query.isDetached());
QCOMPARE_NE(query, original);
QCOMPARE(query, QUrlQuery());
}
}