From 42d55691e494928ea44febc4b086bcdbb1e7d048 Mon Sep 17 00:00:00 2001 From: ecorm Date: Thu, 7 Jan 2016 18:48:49 -0400 Subject: [PATCH] - Fixed encoding of multibyte UTF-8 sequences to JSON (fixes #96). - Added test case for converting multibyte UTF-8 sequences to JSON. --- CHANGELOG.md | 7 +++++++ cppwamp/include/cppwamp/internal/json.ipp | 4 ++-- cppwamp/include/cppwamp/version.hpp | 4 ++-- test/codectestjson.cpp | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abba639e..4a014014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +v0.6.1 +====== +Bug fixes. + +- Fixed encoding of multibyte UTF-8 sequences to JSON (fixes #96). +- Added test case for converting multibyte UTF-8 sequences to JSON. + v0.6.0 ====== Better support for asynchronous RPC and event handlers. diff --git a/cppwamp/include/cppwamp/internal/json.ipp b/cppwamp/include/cppwamp/internal/json.ipp index 98db16f3..2709f195 100644 --- a/cppwamp/include/cppwamp/internal/json.ipp +++ b/cppwamp/include/cppwamp/internal/json.ipp @@ -204,9 +204,9 @@ struct EncodeJson : public Visitor<> case '\t': writeChar(buf, '\\'); writeChar(buf, 't'); return; } - if (c <= 0x1f) + auto n = static_cast(c); + if (n <= 0x1f) { - auto n = static_cast(c); char str[8]; auto length = std::snprintf(str, sizeof(str), "\\u%04X", n); assert(length < sizeof(str)); diff --git a/cppwamp/include/cppwamp/version.hpp b/cppwamp/include/cppwamp/version.hpp index 6fc17b56..06b58c33 100644 --- a/cppwamp/include/cppwamp/version.hpp +++ b/cppwamp/include/cppwamp/version.hpp @@ -20,10 +20,10 @@ #define CPPWAMP_MINOR_VERSION 6 /// Patch version for backwards-compatible bug fixes. -#define CPPWAMP_PATCH_VERSION 6 +#define CPPWAMP_PATCH_VERSION 1 /// Integer version number, computed as `(major*10000) + (minor*100) + patch` -#define CPPWAMP_VERSION 600 +#define CPPWAMP_VERSION 601 namespace wamp { diff --git a/test/codectestjson.cpp b/test/codectestjson.cpp index c1f05a25..054c15cd 100644 --- a/test/codectestjson.cpp +++ b/test/codectestjson.cpp @@ -322,6 +322,24 @@ GIVEN( "an object Variant with control characters in a key" ) } } } +GIVEN( "a string Variant with multi-byte UTF-8 characters" ) +{ + std::string s = "\u0080\u07ff\u0800\uffff\u00010000\u0010ffff"; + Variant v = s; + + WHEN( "encoding to JSON and decoding back" ) + { + std::string encoded; + Json::encode(v, encoded); + Variant decoded; + Json::decode(encoded, decoded); + + THEN( "the decoded Variant matches the original" ) + { + CHECK( decoded == v ); + } + } +} } #endif // #if CPPWAMP_TESTING_CODEC