diff --git a/CHANGELOG.md b/CHANGELOG.md index c73313e0..feb2b888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ HEAD ---- * Improved float serialization when `-fsingle-precision-constant` is used +* Fixed `JsonVariant::is()` that returned true for empty strings v5.13.2 ------- diff --git a/src/ArduinoJson/Polyfills/isInteger.hpp b/src/ArduinoJson/Polyfills/isInteger.hpp index 21f16689..8049079a 100644 --- a/src/ArduinoJson/Polyfills/isInteger.hpp +++ b/src/ArduinoJson/Polyfills/isInteger.hpp @@ -10,10 +10,10 @@ namespace ArduinoJson { namespace Internals { inline bool isInteger(const char* s) { - if (!s) return false; + if (!s || !*s) return false; if (issign(*s)) s++; while (isdigit(*s)) s++; return *s == '\0'; } -} -} +} // namespace Internals +} // namespace ArduinoJson diff --git a/test/Polyfills/isInteger.cpp b/test/Polyfills/isInteger.cpp index f0bec4ae..ec6d020d 100644 --- a/test/Polyfills/isInteger.cpp +++ b/test/Polyfills/isInteger.cpp @@ -12,6 +12,10 @@ TEST_CASE("isInteger()") { REQUIRE_FALSE(isInteger(NULL)); } + SECTION("Empty String") { + REQUIRE_FALSE(isInteger("")); + } + SECTION("FloatNotInteger") { REQUIRE_FALSE(isInteger("3.14")); REQUIRE_FALSE(isInteger("-3.14"));