This commit is contained in:
Niels 2015-07-01 23:08:54 +02:00
parent abd741708d
commit 82a6995306
3 changed files with 14 additions and 2 deletions

View file

@ -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
{

View file

@ -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
{

View file

@ -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<int>(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}");
}
}