Fix removal of QJsonObject properties when assigning undefined

Commit 8010e906d3 accidentally ended up
removing the removal-on-undefined-insertion check by calling insertAt
instead of insert, which had it. This patch moves the check back into
setValueAt.

Change-Id: Ic381e284d3da37e31c4eb29f79dfab9c55c2e3e9
Fixes: QTBUG-77204
Reviewed-by: Liang Qi <liang.qi@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
bb10
Simon Hausmann 2019-07-30 10:51:52 +02:00
parent 23841083e3
commit 31ffc7bf2a
2 changed files with 6 additions and 1 deletions

View File

@ -1476,7 +1476,10 @@ void QJsonObject::setValueAt(int i, const QJsonValue &val)
Q_ASSERT(o && i >= 0 && i < (int)o->length);
QJsonPrivate::Entry *e = o->entryAt(i);
insertAt(i, e->key(), val, true);
if (val.t == QJsonValue::Undefined)
removeAt(i);
else
insertAt(i, e->key(), val, true);
}
/*!

View File

@ -1132,6 +1132,8 @@ void tst_QtJson::undefinedValues()
QJsonObject object;
object.insert("Key", QJsonValue(QJsonValue::Undefined));
QCOMPARE(object.size(), 0);
object["Key"] = QJsonValue(QJsonValue::Undefined);
QCOMPARE(object.size(), 0);
object.insert("Key", QLatin1String("Value"));
QCOMPARE(object.size(), 1);