Fix parsing of unicode escape sequences
authorLars Knoll <lars.knoll@nokia.com>
Tue, 6 Mar 2012 12:05:09 +0000 (13:05 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 6 Mar 2012 23:03:07 +0000 (00:03 +0100)
Change-Id: I63a7cd3a571fb47c97157bcb2ca29c4239c600ba
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/json/qjsonparser.cpp
tests/auto/corelib/json/test.bjson
tests/auto/corelib/json/tst_qtjson.cpp

index 16eedad..a83685d 100644 (file)
@@ -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;
index aa412ee..9a0515f 100644 (file)
Binary files a/tests/auto/corelib/json/test.bjson and b/tests/auto/corelib/json/test.bjson differ
index f5b4f17..f35831c 100644 (file)
@@ -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"