mirror of
				https://github.com/eledio-devices/thirdparty-ArduinoJson.git
				synced 2025-10-31 16:14:11 +01:00 
			
		
		
		
	Fixed parser that incorrectly rejected floats containing a + (issue #349)
				
					
				
			This commit is contained in:
		| @@ -7,6 +7,7 @@ HEAD | ||||
| * Fixed `array[idx].as<JsonVariant>()` and `object[key].as<JsonVariant>()` | ||||
| * Fixed return value of `JsonObject::set()` (issue #350) | ||||
| * Fixed undefined behavior in `Prettyfier` and `Print` (issue #354) | ||||
| * Fixed parser that incorrectly rejected floats containing a `+` (issue #349) | ||||
|  | ||||
| v5.6.6 | ||||
| ------ | ||||
|   | ||||
| @@ -50,7 +50,7 @@ class JsonParser { | ||||
|  | ||||
|   static inline bool isLetterOrNumber(char c) { | ||||
|     return isInRange(c, '0', '9') || isInRange(c, 'a', 'z') || | ||||
|            isInRange(c, 'A', 'Z') || c == '-' || c == '.'; | ||||
|            isInRange(c, 'A', 'Z') || c == '+' || c == '-' || c == '.'; | ||||
|   } | ||||
|  | ||||
|   static inline bool isQuote(char c) { | ||||
|   | ||||
| @@ -17,14 +17,14 @@ template <> | ||||
| inline bool JsonObject::setNodeValue(node_type *node, String &value) { | ||||
|   const char *dup = _buffer->strdup(value); | ||||
|   node->content.value = dup; | ||||
|   return dup; | ||||
|   return dup != NULL; | ||||
| } | ||||
|  | ||||
| template <> | ||||
| inline bool JsonObject::setNodeValue(node_type *node, const String &value) { | ||||
|   const char *dup = _buffer->strdup(value); | ||||
|   node->content.value = dup; | ||||
|   return dup; | ||||
|   return dup != NULL; | ||||
| } | ||||
|  | ||||
| template <> | ||||
|   | ||||
| @@ -23,7 +23,7 @@ class Print { | ||||
|   size_t print(const char* s) { | ||||
|     size_t n = 0; | ||||
|     while (*s) { | ||||
|       n += write(*s++); | ||||
|       n += write(static_cast<uint8_t>(*s++)); | ||||
|     } | ||||
|     return n; | ||||
|   } | ||||
|   | ||||
| @@ -26,9 +26,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)") | ||||
| 		-Winit-self | ||||
| 		-Wmissing-include-dirs | ||||
| 		-Wparentheses | ||||
| 		-Wno-sign-conversion | ||||
| 		-Wno-unused | ||||
| 		-Wno-variadic-macros | ||||
| 		-Wnon-virtual-dtor | ||||
| 		-Wold-style-cast | ||||
| 		-Woverloaded-virtual | ||||
| @@ -63,7 +60,10 @@ endif() | ||||
|  | ||||
| if(MSVC) | ||||
| 	add_definitions(-D_CRT_SECURE_NO_WARNINGS) | ||||
| 	add_compile_options(-W4) | ||||
| 	add_compile_options( | ||||
| 		/W4 # Set warning level | ||||
| 		/WX # Treats all compiler warnings as errors. | ||||
| 	) | ||||
| endif() | ||||
|  | ||||
| add_executable(ArduinoJsonTests ${TESTS_FILES}) | ||||
|   | ||||
| @@ -24,13 +24,29 @@ class JsonParser_Variant_Test : public testing::Test { | ||||
|     EXPECT_STREQ(expected, _result.as<char*>()); | ||||
|   } | ||||
|  | ||||
|   void resultMustEqual(double expected) { | ||||
|     EXPECT_DOUBLE_EQ(expected, _result.as<double>()); | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   void resultTypeMustBe() { | ||||
|     EXPECT_TRUE(_result.is<T>()); | ||||
|   } | ||||
|  | ||||
|   void resultMustBeInvalid() { EXPECT_FALSE(_result.success()); } | ||||
|   void resultMustBeValid() { EXPECT_TRUE(_result.success()); } | ||||
|   void resultMustBeInvalid() { | ||||
|     EXPECT_FALSE(_result.success()); | ||||
|   } | ||||
|   void resultMustBeValid() { | ||||
|     EXPECT_TRUE(_result.success()); | ||||
|   } | ||||
|  | ||||
|   template <typename T> | ||||
|   void verify(const char* input, T expected) { | ||||
|     whenInputIs(input); | ||||
|     resultMustBeValid(); | ||||
|     resultTypeMustBe<T>(); | ||||
|     resultMustEqual(expected); | ||||
|   } | ||||
|  | ||||
|  private: | ||||
|   DynamicJsonBuffer _jsonBuffer; | ||||
| @@ -51,38 +67,29 @@ TEST_F(JsonParser_Variant_Test, EmptyArray) { | ||||
| } | ||||
|  | ||||
| TEST_F(JsonParser_Variant_Test, Integer) { | ||||
|   whenInputIs("42"); | ||||
|   resultMustBeValid(); | ||||
|   resultTypeMustBe<int>(); | ||||
|   resultMustEqual(42); | ||||
|   verify("42", 42); | ||||
|   verify("-42", -42); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonParser_Variant_Test, Double) { | ||||
|   whenInputIs("3.14"); | ||||
|   resultMustBeValid(); | ||||
|   resultTypeMustBe<double>(); | ||||
|   resultMustEqual(3.14); | ||||
|   verify("3.14", 3.14); | ||||
|   verify("3.14", 3.14); | ||||
|   verify("1E+10", 1E+10); | ||||
|   verify("-1E+10", -1E+10); | ||||
|   verify("1.234E+10", 1.234E+10); | ||||
|   verify("1.79769e+308", 1.79769e+308); | ||||
|   verify("-1.79769e+308", -1.79769e+308); | ||||
|   verify("1.7976931348623157e+308", 1.7976931348623157e+308); | ||||
|   verify("0.017976931348623157e+310", 0.017976931348623157e+310); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonParser_Variant_Test, String) { | ||||
|   whenInputIs("\"hello world\""); | ||||
|   resultMustBeValid(); | ||||
|   resultTypeMustBe<char*>(); | ||||
|   resultMustEqual("hello world"); | ||||
|   verify("\"hello world\"", "hello world"); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonParser_Variant_Test, True) { | ||||
|   whenInputIs("true"); | ||||
|   resultMustBeValid(); | ||||
|   resultTypeMustBe<bool>(); | ||||
|   resultMustEqual(true); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonParser_Variant_Test, False) { | ||||
|   whenInputIs("false"); | ||||
|   resultMustBeValid(); | ||||
|   resultTypeMustBe<bool>(); | ||||
|   resultMustEqual(false); | ||||
|   verify("true", true); | ||||
|   verify("false", false); | ||||
| } | ||||
|  | ||||
| TEST_F(JsonParser_Variant_Test, Invalid) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user