diff --git a/src/json.hpp b/src/json.hpp index 5190c64e..879d8be5 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -3978,7 +3978,7 @@ class basic_json { // control characters (everything between 0x00 and 0x1f) // -> create four-digit hex representation - o << "\\u" << std::hex << std::setw(4) << std::setfill('0') << int(c); + o << "\\u" << std::hex << std::setw(4) << std::setfill('0') << int(c) << std::dec; } else { diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 3650c8e7..5a9d4ab3 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -3978,7 +3978,7 @@ class basic_json { // control characters (everything between 0x00 and 0x1f) // -> create four-digit hex representation - o << "\\u" << std::hex << std::setw(4) << std::setfill('0') << int(c); + o << "\\u" << std::hex << std::setw(4) << std::setfill('0') << int(c) << std::dec; } else { diff --git a/test/unit.cpp b/test/unit.cpp index 64e67752..935c665f 100644 --- a/test/unit.cpp +++ b/test/unit.cpp @@ -9276,4 +9276,16 @@ TEST_CASE("regression tests") // we need to cast to int to compile with Catch - the value is int32_t CHECK(static_cast(j["int_1"]) == 1); } + + SECTION("issue #101 - binary string causes numbers to be dumped as hex") + { + int64_t number = 10; + std::string bytes{"\x00" "asdf\n", 6}; + json j; + j["int64"] = number; + j["binary string"] = bytes; + // make sure the number is really printed as decimal "10" and not as + // hexadecimal "a" + CHECK(j.dump() == "{\"binary string\":\"\\u0000asdf\\n\",\"int64\":10}"); + } }