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>bb10
parent
124da60c1d
commit
0411240fda
|
|
@ -629,7 +629,7 @@ public:
|
|||
if (value.latinKey)
|
||||
s += sizeof(ushort) + qFromLittleEndian(*(ushort *) ((const char *)this + sizeof(Entry)));
|
||||
else
|
||||
s += sizeof(uint) + qFromLittleEndian(*(int *) ((const char *)this + sizeof(Entry)));
|
||||
s += sizeof(uint) + sizeof(ushort)*qFromLittleEndian(*(int *) ((const char *)this + sizeof(Entry)));
|
||||
return alignedSize(s);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue