Skip to content

Commit

Permalink
WireResponseEncoder::encode now outputs raw utf8 by default.
Browse files Browse the repository at this point in the history
This modifies the WireResponseEncoder to always use the raw_utf8
option provided by the new version of json_spirit.

According to the IETF RFC8259:
"JSON text exchanged between systems that are not part of a closed
   ecosystem MUST be encoded using UTF-8 [RFC3629]."
https://tools.ietf.org/html/rfc8259
  • Loading branch information
src committed Jul 1, 2019
1 parent ee964b2 commit 581b3c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/connectors/wire/WireProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <json_spirit/json_spirit_reader_template.h>
#include <json_spirit/json_spirit_writer_template.h>
#include <json_spirit/json_spirit_writer_options.h>

#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
Expand Down Expand Up @@ -231,7 +232,7 @@ namespace {
jsonOutput.clear();
response.accept(*this);
const mValue v(jsonOutput);
return write_string(v, false);
return write_string(v, ::raw_utf8);
}

void visit(const SuccessResponse& /*response*/) {
Expand Down
16 changes: 1 addition & 15 deletions tests/integration/WireProtocolTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,11 @@ TEST_F(WireMessageCodecTest, encodesResponseUsingRawUtf8) {
StepMatchesResponse response(matches);

// clang-format off
// EXPECTED:
// EXPECT_THAT(codec.encode(response), StrEq(
// "[\"success\",[{"
// "\"args\":[{"
// "\"pos\":5,"
// "\"val\":\"カラオケ機\""
// "},{"
// "\"pos\":18,"
// "\"val\":\"ASCII\""
// "}],"
// "\"id\":\"1234\","
// "\"regexp\":\"Some (.+) regexp (.+)\""
// "}]]"));
// ACTUAL:
EXPECT_THAT(codec.encode(response), StrEq(
"[\"success\",[{"
"\"args\":[{"
"\"pos\":5,"
"\"val\":\"\\u00E3\\u0082\\u00AB\\u00E3\\u0083\\u00A9\\u00E3\\u0082\\u00AA\\u00E3\\u0082\\u00B1\\u00E6\\u00A9\\u009F\""
"\"val\":\"カラオケ機\""
"},{"
"\"pos\":18,"
"\"val\":\"ASCII\""
Expand Down

0 comments on commit 581b3c8

Please sign in to comment.