diff options
author | Lars Knoll <lars.knoll@theqtcompany.com> | 2015-03-17 16:01:05 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@digia.com> | 2015-03-18 07:34:59 +0000 |
commit | 0411240fdaada112d150f28f82973beb15478b1d (patch) | |
tree | 2349e4feaf90db735a83788f8a9792e72d5f378e /tests/auto/corelib/json | |
parent | 124da60c1de2cc63ad8692bd3a72e8769c6c1e5a (diff) |
Make sure remove() doesn't corrupt the json object
When using non latin keys, remove() could cause corruption
of the json object.
Task-number: QTBUG-42270
Change-Id: I7305e57ebb78630a9bf68bc4f831a6d1646abb79
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/json')
-rw-r--r-- | tests/auto/corelib/json/tst_qtjson.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index 18d1ecd33c..884c4b3850 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -145,6 +145,8 @@ private Q_SLOTS: void unicodeKeys(); void garbageAtEnd(); + + void removeNonLatinKey(); private: QString testDataDir; }; @@ -2776,5 +2778,24 @@ void tst_QtJson::garbageAtEnd() QVERIFY(!doc.isEmpty()); } +void tst_QtJson::removeNonLatinKey() +{ + const QString nonLatinKeyName = QString::fromUtf8("Атрибут100500"); + + QJsonObject sourceObject; + + sourceObject.insert("code", 1); + sourceObject.remove("code"); + + sourceObject.insert(nonLatinKeyName, 1); + + const QByteArray json = QJsonDocument(sourceObject).toJson(); + const QJsonObject restoredObject = QJsonDocument::fromJson(json).object(); + + QCOMPARE(sourceObject.keys(), restoredObject.keys()); + QVERIFY(sourceObject.contains(nonLatinKeyName)); + QVERIFY(restoredObject.contains(nonLatinKeyName)); +} + QTEST_MAIN(tst_QtJson) #include "tst_qtjson.moc" |