mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	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