Skip to content

Commit 42d5569

Browse files
committed
- Fixed encoding of multibyte UTF-8 sequences to JSON (fixes #96).
- Added test case for converting multibyte UTF-8 sequences to JSON.
1 parent a0cf8c0 commit 42d5569

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
v0.6.1
2+
======
3+
Bug fixes.
4+
5+
- Fixed encoding of multibyte UTF-8 sequences to JSON (fixes #96).
6+
- Added test case for converting multibyte UTF-8 sequences to JSON.
7+
18
v0.6.0
29
======
310
Better support for asynchronous RPC and event handlers.

cppwamp/include/cppwamp/internal/json.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ struct EncodeJson : public Visitor<>
204204
case '\t': writeChar(buf, '\\'); writeChar(buf, 't'); return;
205205
}
206206

207-
if (c <= 0x1f)
207+
auto n = static_cast<unsigned int>(c);
208+
if (n <= 0x1f)
208209
{
209-
auto n = static_cast<unsigned int>(c);
210210
char str[8];
211211
auto length = std::snprintf(str, sizeof(str), "\\u%04X", n);
212212
assert(length < sizeof(str));

cppwamp/include/cppwamp/version.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#define CPPWAMP_MINOR_VERSION 6
2121

2222
/// Patch version for backwards-compatible bug fixes.
23-
#define CPPWAMP_PATCH_VERSION 6
23+
#define CPPWAMP_PATCH_VERSION 1
2424

2525
/// Integer version number, computed as `(major*10000) + (minor*100) + patch`
26-
#define CPPWAMP_VERSION 600
26+
#define CPPWAMP_VERSION 601
2727

2828
namespace wamp
2929
{

test/codectestjson.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,24 @@ GIVEN( "an object Variant with control characters in a key" )
322322
}
323323
}
324324
}
325+
GIVEN( "a string Variant with multi-byte UTF-8 characters" )
326+
{
327+
std::string s = "\u0080\u07ff\u0800\uffff\u00010000\u0010ffff";
328+
Variant v = s;
329+
330+
WHEN( "encoding to JSON and decoding back" )
331+
{
332+
std::string encoded;
333+
Json::encode(v, encoded);
334+
Variant decoded;
335+
Json::decode(encoded, decoded);
336+
337+
THEN( "the decoded Variant matches the original" )
338+
{
339+
CHECK( decoded == v );
340+
}
341+
}
342+
}
325343
}
326344

327345
#endif // #if CPPWAMP_TESTING_CODEC

0 commit comments

Comments
 (0)