From 853845a4a2570302def9526a99f2b09433c286c5 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 5 Sep 2014 12:58:19 +0200 Subject: Fix bugs in internal comparison operators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The comparison operators between QJsonPrivate::String and QJsonPrivate::Latin1String weren't all correct, leading to wrong sorting of keys in QJsonObjects when the keys were outside of the latin1 range and resulting lookup errors. Task-number: QTBUG-41100 Change-Id: Idceff615f85d7ab874ad2a8e4a6c1ce8c2aa0f65 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/json/tst_qtjson.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/auto/corelib/json') diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index d4ce123fcc..ba19e4855d 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -149,6 +149,8 @@ private Q_SLOTS: void arrayInitializerList(); void objectInitializerList(); + + void unicodeKeys(); private: QString testDataDir; }; @@ -2753,5 +2755,27 @@ void tst_QtJson::objectInitializerList() #endif } +void tst_QtJson::unicodeKeys() +{ + QByteArray json = "{" + "\"x\u2090_1\": \"hello_1\"," + "\"y\u2090_2\": \"hello_2\"," + "\"T\u2090_3\": \"hello_3\"," + "\"xyz_4\": \"hello_4\"," + "\"abc_5\": \"hello_5\"" + "}"; + + QJsonParseError error; + QJsonDocument doc = QJsonDocument::fromJson(json, &error); + QVERIFY(error.error == QJsonParseError::NoError); + QJsonObject o = doc.object(); + + QCOMPARE(o.keys().size(), 5); + Q_FOREACH (const QString &key, o.keys()) { + QString suffix = key.mid(key.indexOf(QLatin1Char('_'))); + QCOMPARE(o[key].toString(), QString("hello") + suffix); + } +} + QTEST_MAIN(tst_QtJson) #include "tst_qtjson.moc" -- cgit v1.2.3