diff --git a/src/json.hpp b/src/json.hpp index 33f08761..df162274 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -6644,7 +6644,7 @@ class serializer { if (ensure_ascii and (s[i] & 0x80 or s[i] == 0x7F)) { - const auto bytes = bytes_following(s[i] & 0xFF); + const auto bytes = bytes_following(static_cast(s[i])); if (bytes == std::string::npos) { // invalid characters are treated as is, so no @@ -6821,7 +6821,7 @@ class serializer if ((0x00 <= s[i] and s[i] <= 0x1F) or (ensure_ascii and (s[i] & 0x80 or s[i] == 0x7F))) { - const auto bytes = bytes_following(s[i] & 0xFF); + const auto bytes = bytes_following(static_cast(s[i])); if (bytes == std::string::npos) { // copy invalid character as is diff --git a/test/src/unit-convenience.cpp b/test/src/unit-convenience.cpp index 23d66b8a..cd4f9e3f 100644 --- a/test/src/unit-convenience.cpp +++ b/test/src/unit-convenience.cpp @@ -32,6 +32,15 @@ SOFTWARE. #include "json.hpp" using nlohmann::json; +void check_escaped(const char* original, const char* escaped, const bool ensure_ascii = false); +void check_escaped(const char* original, const char* escaped, const bool ensure_ascii) +{ + std::stringstream ss; + json::serializer s(nlohmann::detail::output_adapter_factory::create(ss), ' '); + s.dump_escaped(original, ensure_ascii); + CHECK(ss.str() == escaped); +} + TEST_CASE("convenience functions") { SECTION("type name as string") @@ -49,16 +58,6 @@ TEST_CASE("convenience functions") SECTION("string escape") { - const auto check_escaped = [](const char* original, - const char* escaped, - const bool ensure_ascii = false) - { - std::stringstream ss; - json::serializer s(nlohmann::detail::output_adapter_factory::create(ss), ' '); - s.dump_escaped(original, ensure_ascii); - CHECK(ss.str() == escaped); - }; - check_escaped("\"", "\\\""); check_escaped("\\", "\\\\"); check_escaped("\b", "\\b");