summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-03-06 13:05:09 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-07 00:03:07 +0100
commit53bbea232830af3f056cd8253c4ff4dd33f525c7 (patch)
treef47a5e83f8c01540b4ff7d4db4fb58769b90d9f1
parent7ae6a6e744f92db2626b7c9b38175dc4140a4eaf (diff)
Fix parsing of unicode escape sequences
Change-Id: I63a7cd3a571fb47c97157bcb2ca29c4239c600ba Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/json/qjsonparser.cpp4
-rw-r--r--tests/auto/corelib/json/test.bjsonbin60992 -> 60992 bytes
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp16
3 files changed, 18 insertions, 2 deletions
diff --git a/src/corelib/json/qjsonparser.cpp b/src/corelib/json/qjsonparser.cpp
index 16eedadf1a..a83685da22 100644
--- a/src/corelib/json/qjsonparser.cpp
+++ b/src/corelib/json/qjsonparser.cpp
@@ -584,9 +584,9 @@ static inline bool addHexDigit(char digit, uint *result)
if (digit >= '0' && digit <= '9')
*result |= (digit - '0');
else if (digit >= 'a' && digit <= 'f')
- *result |= (digit - 'a');
+ *result |= (digit - 'a') + 10;
else if (digit >= 'A' && digit <= 'F')
- *result |= (digit - 'A');
+ *result |= (digit - 'A') + 10;
else
return false;
return true;
diff --git a/tests/auto/corelib/json/test.bjson b/tests/auto/corelib/json/test.bjson
index aa412eec67..9a0515f3ef 100644
--- a/tests/auto/corelib/json/test.bjson
+++ b/tests/auto/corelib/json/test.bjson
Binary files differ
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index f5b4f17732..f35831c900 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -115,6 +115,8 @@ private Q_SLOTS:
void testCompaction();
void testDebugStream();
void testCompactionError();
+
+ void parseUnicodeEscapes();
private:
QString testDataDir;
};
@@ -1758,5 +1760,19 @@ void TestQtJson::testCompactionError()
}
}
+void TestQtJson::parseUnicodeEscapes()
+{
+ const QByteArray json = "[ \"A\\u00e4\\u00C4\" ]";
+
+ QJsonDocument doc = QJsonDocument::fromJson(json);
+ QJsonArray array = doc.array();
+
+ QString result = QLatin1String("A");
+ result += QChar(0xe4);
+ result += QChar(0xc4);
+
+ QCOMPARE(array.first().toString(), result);
+}
+
QTEST_MAIN(TestQtJson)
#include "tst_qtjson.moc"