summaryrefslogtreecommitdiffstats
path: root/src/corelib/json
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2012-05-10 13:24:28 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-10 13:50:35 +0200
commit1f9a958e3668a32270d63dc4216804ef6333c9f3 (patch)
tree1d6ac51f268cc6f592bd475a51488bc31615ba51 /src/corelib/json
parentf6bd10b8ff5aacc6d214d8dd5be570a5301f9433 (diff)
Correctly parse json documents with a leading BOM
A leading byte order mark is valid in utf-8 and we should parse documents starting with those correctly. Change-Id: Id85398ff6e05b93ceefbaf4a6de5571d5e61ca13 Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Diffstat (limited to 'src/corelib/json')
-rw-r--r--src/corelib/json/qjsonparser.cpp16
-rw-r--r--src/corelib/json/qjsonparser_p.h1
2 files changed, 15 insertions, 2 deletions
diff --git a/src/corelib/json/qjsonparser.cpp b/src/corelib/json/qjsonparser.cpp
index 8c5693c9be..5fecb8d4e7 100644
--- a/src/corelib/json/qjsonparser.cpp
+++ b/src/corelib/json/qjsonparser.cpp
@@ -185,7 +185,16 @@ enum {
Quote = 0x22
};
-
+void Parser::eatBOM()
+{
+ // eat UTF-8 byte order mark
+ uchar utf8bom[3] = { 0xef, 0xbb, 0xbf };
+ if (end - json > 3 &&
+ (uchar)json[0] == utf8bom[0] &&
+ (uchar)json[1] == utf8bom[1] &&
+ (uchar)json[2] == utf8bom[2])
+ json += 3;
+}
bool Parser::eatSpace()
{
@@ -244,8 +253,10 @@ QJsonDocument Parser::parse(QJsonParseError *error)
current = sizeof(QJsonPrivate::Header);
+ eatBOM();
char token = nextToken();
- DEBUG << token;
+
+ DEBUG << hex << (uint)token;
if (token == BeginArray) {
if (!parseArray())
goto error;
@@ -253,6 +264,7 @@ QJsonDocument Parser::parse(QJsonParseError *error)
if (!parseObject())
goto error;
} else {
+ lastError = QJsonParseError::IllegalValue;
goto error;
}
diff --git a/src/corelib/json/qjsonparser_p.h b/src/corelib/json/qjsonparser_p.h
index 20e57dcf26..8085edb2e0 100644
--- a/src/corelib/json/qjsonparser_p.h
+++ b/src/corelib/json/qjsonparser_p.h
@@ -84,6 +84,7 @@ public:
private:
+ inline void eatBOM();
inline bool eatSpace();
inline char nextToken();