summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2019-07-30 10:51:52 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-07-30 11:08:24 +0200
commit31ffc7bf2a0efe40116764a8c84939d2df4cdeae (patch)
tree9794916f1815b58d17e8e4201aa4ee4e7474f757
parent23841083e33c85baed3441c7cc80dafcf5bea0d9 (diff)
Fix removal of QJsonObject properties when assigning undefined
Commit 8010e906d3612aface0daccde41d1a65fca04b0c 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>
-rw-r--r--src/corelib/serialization/qjsonobject.cpp5
-rw-r--r--tests/auto/corelib/serialization/json/tst_qtjson.cpp2
2 files changed, 6 insertions, 1 deletions
diff --git a/src/corelib/serialization/qjsonobject.cpp b/src/corelib/serialization/qjsonobject.cpp
index 99ab25f265..329bc4d2c9 100644
--- a/src/corelib/serialization/qjsonobject.cpp
+++ b/src/corelib/serialization/qjsonobject.cpp
@@ -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);
}
/*!
diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
index 7b055b5b63..57aa67c142 100644
--- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
@@ -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);