mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Fixed null values that could be pass to strcmp() (closes #745)
				
					
				
			This commit is contained in:
		| @@ -149,4 +149,15 @@ TEST_CASE("JsonObject::operator[]") { | ||||
|     const size_t expectedSize = JSON_OBJECT_SIZE(1) + 12; | ||||
|     REQUIRE(expectedSize <= _jsonBuffer.size()); | ||||
|   } | ||||
|  | ||||
|   SECTION("should ignore null key") { | ||||
|     // object must have a value to make a call to strcmp() | ||||
|     _object["dummy"] = 42; | ||||
|  | ||||
|     const char* null = 0; | ||||
|     _object[null] = 666; | ||||
|  | ||||
|     REQUIRE(_object.size() == 1); | ||||
|     REQUIRE(_object[null] == 0); | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -5,6 +5,8 @@ | ||||
| #include <ArduinoJson.h> | ||||
| #include <catch.hpp> | ||||
|  | ||||
| static const char* null = 0; | ||||
|  | ||||
| template <typename T> | ||||
| void checkEquals(JsonVariant a, T b) { | ||||
|   REQUIRE(b == a); | ||||
| @@ -96,38 +98,69 @@ TEST_CASE("JsonVariant comparisons") { | ||||
|     checkComparisons<unsigned short>(122, 123, 124); | ||||
|   } | ||||
|  | ||||
|   SECTION("null") { | ||||
|     JsonVariant variant = null; | ||||
|  | ||||
|     REQUIRE(variant == variant); | ||||
|     REQUIRE_FALSE(variant != variant); | ||||
|  | ||||
|     REQUIRE(variant == null); | ||||
|     REQUIRE_FALSE(variant != null); | ||||
|  | ||||
|     REQUIRE(variant != "null"); | ||||
|     REQUIRE_FALSE(variant == "null"); | ||||
|   } | ||||
|  | ||||
|   SECTION("StringLiteral") { | ||||
|     DynamicJsonBuffer jsonBuffer; | ||||
|     JsonVariant variant = jsonBuffer.parse("\"hello\""); | ||||
|  | ||||
|     REQUIRE(variant == variant); | ||||
|     REQUIRE_FALSE(variant != variant); | ||||
|  | ||||
|     REQUIRE(variant == "hello"); | ||||
|     REQUIRE_FALSE(variant != "hello"); | ||||
|  | ||||
|     REQUIRE(variant != "world"); | ||||
|     REQUIRE_FALSE(variant == "world"); | ||||
|  | ||||
|     REQUIRE(variant != null); | ||||
|     REQUIRE_FALSE(variant == null); | ||||
|  | ||||
|     REQUIRE("hello" == variant); | ||||
|     REQUIRE_FALSE("hello" != variant); | ||||
|  | ||||
|     REQUIRE("world" != variant); | ||||
|     REQUIRE_FALSE("world" == variant); | ||||
|  | ||||
|     REQUIRE(null != variant); | ||||
|     REQUIRE_FALSE(null == variant); | ||||
|   } | ||||
|  | ||||
|   SECTION("String") { | ||||
|     DynamicJsonBuffer jsonBuffer; | ||||
|     JsonVariant variant = jsonBuffer.parse("\"hello\""); | ||||
|  | ||||
|     REQUIRE(variant == variant); | ||||
|     REQUIRE_FALSE(variant != variant); | ||||
|  | ||||
|     REQUIRE(variant == std::string("hello")); | ||||
|     REQUIRE_FALSE(variant != std::string("hello")); | ||||
|  | ||||
|     REQUIRE(variant != std::string("world")); | ||||
|     REQUIRE_FALSE(variant == std::string("world")); | ||||
|  | ||||
|     REQUIRE(variant != null); | ||||
|     REQUIRE_FALSE(variant == null); | ||||
|  | ||||
|     REQUIRE(std::string("hello") == variant); | ||||
|     REQUIRE_FALSE(std::string("hello") != variant); | ||||
|  | ||||
|     REQUIRE(std::string("world") != variant); | ||||
|     REQUIRE_FALSE(std::string("world") == variant); | ||||
|  | ||||
|     REQUIRE(null != variant); | ||||
|     REQUIRE_FALSE(null == variant); | ||||
|   } | ||||
|  | ||||
|   SECTION("IntegerInVariant") { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user