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