QJsonObject::take: add missing detach() call
We were modifying shared objects. Pick-to: 6.0 5.15 Fixes: QTBUG-89625 Change-Id: Id6bc735b79cf4beb9454fffd165c56476a5dec04 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>bb10
parent
6da6b6da44
commit
00b759a8d0
|
|
@ -617,6 +617,7 @@ QJsonValue QJsonObject::takeImpl(T key)
|
|||
if (!keyExists)
|
||||
return QJsonValue(QJsonValue::Undefined);
|
||||
|
||||
detach();
|
||||
const QJsonValue v = QJsonPrivate::Value::fromTrustedCbor(o->extractAt(index + 1));
|
||||
removeAt(index / 2);
|
||||
return v;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ private Q_SLOTS:
|
|||
void testNumberComparisons();
|
||||
|
||||
void testObjectSimple();
|
||||
void testObjectTakeDetach();
|
||||
void testObjectSmallKeys();
|
||||
void testObjectInsertCopies();
|
||||
void testArraySimple();
|
||||
|
|
@ -575,6 +576,24 @@ void tst_QtJson::testObjectSimple()
|
|||
QCOMPARE(subvalue.toObject(), subobject);
|
||||
}
|
||||
|
||||
void tst_QtJson::testObjectTakeDetach()
|
||||
{
|
||||
QJsonObject object1, object2;
|
||||
object1["key1"] = 1;
|
||||
object1["key2"] = 2;
|
||||
object2 = object1;
|
||||
|
||||
object1.take("key2");
|
||||
object1.remove("key1");
|
||||
QVERIFY(!object1.contains("key1"));
|
||||
QVERIFY(object2.contains("key1"));
|
||||
QVERIFY(object2.value("key1").isDouble());
|
||||
|
||||
QVERIFY(!object1.contains("key2"));
|
||||
QVERIFY(object2.contains("key2"));
|
||||
QVERIFY(object2.value("key2").isDouble());
|
||||
}
|
||||
|
||||
void tst_QtJson::testObjectSmallKeys()
|
||||
{
|
||||
QJsonObject data1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue