Skip to content

Commit

Permalink
- Fixed encoding of multibyte UTF-8 sequences to JSON (fixes #96).
Browse files Browse the repository at this point in the history
- Added test case for converting multibyte UTF-8 sequences to JSON.
  • Loading branch information
ecorm committed Jan 7, 2016
1 parent a0cf8c0 commit 42d5569
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 2 additions & 2 deletions cppwamp/include/cppwamp/internal/json.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ struct EncodeJson : public Visitor<>
case '\t': writeChar(buf, '\\'); writeChar(buf, 't'); return;
}

if (c <= 0x1f)
auto n = static_cast<unsigned int>(c);
if (n <= 0x1f)
{
auto n = static_cast<unsigned int>(c);
char str[8];
auto length = std::snprintf(str, sizeof(str), "\\u%04X", n);
assert(length < sizeof(str));
Expand Down
4 changes: 2 additions & 2 deletions cppwamp/include/cppwamp/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
18 changes: 18 additions & 0 deletions test/codectestjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 42d5569

Please sign in to comment.