Skip to content

Commit

Permalink
Merge pull request #126 from EOSIO/jjz-merge-PR#125
Browse files Browse the repository at this point in the history
to_json: use letter escapes #125
  • Loading branch information
heifner authored May 13, 2021
2 parents 7ebffd3 + b625f72 commit e44ac86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions include/eosio/to_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ void to_json(std::string_view sv, S& stream) {
stream.write("\\\"", 2);
} else if (*begin == '\\') {
stream.write("\\\\", 2);
} else if (*begin == '\b') {
stream.write("\\b", 2);
} else if (*begin == '\f') {
stream.write("\\f", 2);
} else if (*begin == '\n') {
stream.write("\\n", 2);
} else if (*begin == '\r') {
stream.write("\\r", 2);
} else if (*begin == '\t') {
stream.write("\\t", 2);
} else {
stream.write("\\u00", 4);
stream.write(hex_digits[(unsigned char)(*begin) >> 4]);
Expand Down
3 changes: 2 additions & 1 deletion src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,8 @@ void check_types() {
check(abieos_bin_to_json(context, 0, "string", "\x11invalid utf8: \xff\xfe\xfd", 18) ==
std::string(R"("invalid utf8: ???")"),
"invalid utf8");
check(abieos_bin_to_json(context, 0, "string", "\4\xe8\xbf\x99\n", 5) == std::string("\"\xe8\xbf\x99\\u000A\""),
check(abieos_bin_to_json(context, 0, "string", "\x08\xe8\xbf\x99\b\f\n\r\t", 9) ==
std::string("\"\xe8\xbf\x99\\b\\f\\n\\r\\t\""),
"escaping");
check_error(context, "Stream overrun", [&] { return abieos_hex_to_json(context, 0, "string", "01"); });
check_type(context, 0, "checksum160", R"("0000000000000000000000000000000000000000")");
Expand Down

0 comments on commit e44ac86

Please sign in to comment.