Support NUL inside string values (issue #1646)

This commit is contained in:
Benoit Blanchon
2021-11-21 15:07:56 +01:00
parent a27398e445
commit be70f6ddd7
22 changed files with 144 additions and 59 deletions

View File

@ -45,3 +45,13 @@ TEST_CASE("serialize JsonObject to std::string") {
REQUIRE("{\r\n \"key\": \"value\"\r\n}" == json);
}
}
TEST_CASE("serialize an std::string containing a NUL") {
StaticJsonDocument<256> doc;
doc.set(std::string("hello\0world", 11));
CHECK(doc.memoryUsage() == 12);
std::string json;
serializeJson(doc, json);
CHECK("\"hello\\u0000world\"" == json);
}