mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Fixed deserializeJson() when input contains duplicate keys (fixes #1095)
This commit is contained in:
		| @@ -6,6 +6,7 @@ HEAD | |||||||
|  |  | ||||||
| * Added support for custom writer classes (issue #1088) | * Added support for custom writer classes (issue #1088) | ||||||
| * Added conversion from `JsonArray` and `JsonObject` to `bool`, to be consistent with `JsonVariant` | * Added conversion from `JsonArray` and `JsonObject` to `bool`, to be consistent with `JsonVariant` | ||||||
|  | * Fixed `deserializeJson()` when input contains duplicate keys (issue #1095) | ||||||
|  |  | ||||||
| v6.12.0 (2019-09-05) | v6.12.0 (2019-09-05) | ||||||
| ------- | ------- | ||||||
|   | |||||||
| @@ -277,6 +277,7 @@ TEST_CASE("deserialize JSON object") { | |||||||
|       DeserializationError err = deserializeJson(doc, "{a:{b:{c:1}},a:2}"); |       DeserializationError err = deserializeJson(doc, "{a:{b:{c:1}},a:2}"); | ||||||
|  |  | ||||||
|       REQUIRE(err == DeserializationError::Ok); |       REQUIRE(err == DeserializationError::Ok); | ||||||
|  |       REQUIRE(doc["a"] == 2); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -130,15 +130,21 @@ class JsonDeserializer { | |||||||
|  |  | ||||||
|     // Read each key value pair |     // Read each key value pair | ||||||
|     for (;;) { |     for (;;) { | ||||||
|       // Allocate slot in object |  | ||||||
|       VariantSlot *slot = object.addSlot(_pool); |  | ||||||
|       if (!slot) return DeserializationError::NoMemory; |  | ||||||
|  |  | ||||||
|       // Parse key |       // Parse key | ||||||
|       const char *key; |       const char *key; | ||||||
|       err = parseKey(key); |       err = parseKey(key); | ||||||
|       if (err) return err; |       if (err) return err; | ||||||
|       slot->setOwnedKey(make_not_null(key)); |  | ||||||
|  |       VariantData *variant = object.get(adaptString(key)); | ||||||
|  |       if (!variant) { | ||||||
|  |         // Allocate slot in object | ||||||
|  |         VariantSlot *slot = object.addSlot(_pool); | ||||||
|  |         if (!slot) return DeserializationError::NoMemory; | ||||||
|  |  | ||||||
|  |         slot->setOwnedKey(make_not_null(key)); | ||||||
|  |  | ||||||
|  |         variant = slot->data(); | ||||||
|  |       } | ||||||
|  |  | ||||||
|       // Skip spaces |       // Skip spaces | ||||||
|       err = skipSpacesAndComments(); |       err = skipSpacesAndComments(); | ||||||
| @@ -147,7 +153,7 @@ class JsonDeserializer { | |||||||
|  |  | ||||||
|       // Parse value |       // Parse value | ||||||
|       _nestingLimit--; |       _nestingLimit--; | ||||||
|       err = parseVariant(*slot->data()); |       err = parseVariant(*variant); | ||||||
|       _nestingLimit++; |       _nestingLimit++; | ||||||
|       if (err) return err; |       if (err) return err; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user