diff options
author | Liang Qi <liang.qi@qt.io> | 2019-05-15 07:11:41 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2019-05-15 07:11:41 +0200 |
commit | c0359bd3c3a098ace9d2fa7ee91c33b24a8d9477 (patch) | |
tree | 9bcae3bff2ccef2b020c7a9ef25b3643e9ae556f /src/corelib/serialization | |
parent | 68eea0196ebf30617e7d837ac5f61aaeeb814692 (diff) | |
parent | 1e5deb06416b6efc33a2009d9678fd8f743c5ce7 (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Conflicts:
src/corelib/global/qfloat16.cpp
src/corelib/global/qfloat16.h
src/plugins/platforms/windows/qwindowswindow.cpp
Change-Id: I0938aaa6a9771f55e48c95ed29f6f5291431b947
Diffstat (limited to 'src/corelib/serialization')
-rw-r--r-- | src/corelib/serialization/qjsonwriter.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/corelib/serialization/qjsonwriter.cpp b/src/corelib/serialization/qjsonwriter.cpp index 12ce20ef09..5b246837d2 100644 --- a/src/corelib/serialization/qjsonwriter.cpp +++ b/src/corelib/serialization/qjsonwriter.cpp @@ -58,7 +58,6 @@ static inline uchar hexdig(uint u) static QByteArray escapedString(const QString &s) { - const uchar replacement = '?'; QByteArray ba(s.length(), Qt::Uninitialized); uchar *cursor = reinterpret_cast<uchar *>(const_cast<char *>(ba.constData())); @@ -111,9 +110,14 @@ static QByteArray escapedString(const QString &s) } else { *cursor++ = (uchar)u; } - } else { - if (QUtf8Functions::toUtf8<QUtf8BaseTraits>(u, cursor, src, end) < 0) - *cursor++ = replacement; + } else if (QUtf8Functions::toUtf8<QUtf8BaseTraits>(u, cursor, src, end) < 0) { + // failed to get valid utf8 use JSON escape sequence + *cursor++ = '\\'; + *cursor++ = 'u'; + *cursor++ = hexdig(u>>12 & 0x0f); + *cursor++ = hexdig(u>>8 & 0x0f); + *cursor++ = hexdig(u>>4 & 0x0f); + *cursor++ = hexdig(u & 0x0f); } } |