forked from bblanchon/ArduinoJson
Support NUL inside string values (issue #1646)
This commit is contained in:
@ -63,6 +63,10 @@ TEST_CASE("serializeJson(JsonVariant)") {
|
||||
SECTION("Escape tab") {
|
||||
check(std::string("hello\tworld"), "\"hello\\tworld\"");
|
||||
}
|
||||
|
||||
SECTION("NUL char") {
|
||||
check(std::string("hello\0world", 11), "\"hello\\u0000world\"");
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("SerializedValue<const char*>") {
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user