mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Fix lax parsing of true, false, and null (fixes #1781)
				
					
				
			This commit is contained in:
		| @@ -71,6 +71,15 @@ TEST_CASE("Filtering") { | ||||
|       "{\"example\":null}", | ||||
|       JSON_OBJECT_SIZE(1) + 8 | ||||
|     }, | ||||
|     { | ||||
|       // Member is a number, but filter wants an array | ||||
|       "{\"example\":42}", | ||||
|       "{\"example\":[true]}", | ||||
|       10, | ||||
|       DeserializationError::Ok, | ||||
|       "{\"example\":null}", | ||||
|       JSON_OBJECT_SIZE(1) + 8 | ||||
|     }, | ||||
|     { | ||||
|       // Input is an array, but filter wants an object | ||||
|       "[\"hello\",\"world\"]", | ||||
| @@ -117,7 +126,7 @@ TEST_CASE("Filtering") { | ||||
|       JSON_OBJECT_SIZE(1) + 8 | ||||
|     }, | ||||
|     { | ||||
|       // can skip a boolean | ||||
|       // skip false | ||||
|       "{\"a_bool\":false,example:42}", | ||||
|       "{\"example\":true}", | ||||
|       10, | ||||
| @@ -125,6 +134,24 @@ TEST_CASE("Filtering") { | ||||
|       "{\"example\":42}", | ||||
|       JSON_OBJECT_SIZE(1) + 8 | ||||
|     }, | ||||
|     { | ||||
|       // skip true | ||||
|       "{\"a_bool\":true,example:42}", | ||||
|       "{\"example\":true}", | ||||
|       10, | ||||
|       DeserializationError::Ok, | ||||
|       "{\"example\":42}", | ||||
|       JSON_OBJECT_SIZE(1) + 8 | ||||
|     }, | ||||
|     { | ||||
|       // skip null | ||||
|       "{\"a_bool\":null,example:42}", | ||||
|       "{\"example\":true}", | ||||
|       10, | ||||
|       DeserializationError::Ok, | ||||
|       "{\"example\":42}", | ||||
|       JSON_OBJECT_SIZE(1) + 8 | ||||
|     }, | ||||
|     { | ||||
|       // can skip a double-quoted string | ||||
|       "{\"a_double_quoted_string\":\"hello\",example:42}", | ||||
| @@ -618,7 +645,7 @@ TEST_CASE("Filtering") { | ||||
|       0 | ||||
|     }, | ||||
|     { | ||||
|       // incomplete after after key of a skipped object | ||||
|       // incomplete comment after key of a skipped object | ||||
|       "{\"example\"/*:2}", | ||||
|       "false", | ||||
|       10, | ||||
| @@ -636,7 +663,7 @@ TEST_CASE("Filtering") { | ||||
|       0 | ||||
|     }, | ||||
|     { | ||||
|       // incomplete after after value of a skipped object | ||||
|       // incomplete comment after value of a skipped object | ||||
|       "{\"example\":2/*}", | ||||
|       "false", | ||||
|       10, | ||||
| @@ -644,6 +671,15 @@ TEST_CASE("Filtering") { | ||||
|       "null", | ||||
|       0 | ||||
|     }, | ||||
|      { | ||||
|       // incomplete comment after comma in skipped object | ||||
|       "{\"example\":2,/*}", | ||||
|       "false", | ||||
|       10, | ||||
|       DeserializationError::IncompleteInput, | ||||
|       "null", | ||||
|       0 | ||||
|     }, | ||||
|   };  // clang-format on | ||||
|  | ||||
|   for (size_t i = 0; i < sizeof(testCases) / sizeof(testCases[0]); i++) { | ||||
|   | ||||
| @@ -9,7 +9,8 @@ | ||||
| TEST_CASE("Invalid JSON input") { | ||||
|   const char* testCases[] = {"'\\u'",     "'\\u000g'", "'\\u000'", "'\\u000G'", | ||||
|                              "'\\u000/'", "\\x1234",   "6a9",      "1,", | ||||
|                              "2]",        "3}"}; | ||||
|                              "nulL",      "tru3",      "fals3",    "2]", | ||||
|                              "3}"}; | ||||
|   const size_t testCount = sizeof(testCases) / sizeof(testCases[0]); | ||||
|  | ||||
|   DynamicJsonDocument doc(4096); | ||||
| @@ -23,9 +24,6 @@ TEST_CASE("Invalid JSON input") { | ||||
|  | ||||
| TEST_CASE("Invalid JSON input that should pass") { | ||||
|   const char* testCases[] = { | ||||
|       "nulL", | ||||
|       "tru3", | ||||
|       "fals3", | ||||
|       "'\\ud83d'",         // leading surrogate without a trailing surrogate | ||||
|       "'\\udda4'",         // trailing surrogate without a leading surrogate | ||||
|       "'\\ud83d\\ud83d'",  // two leading surrogates | ||||
|   | ||||
		Reference in New Issue
	
	Block a user