Fixed reading "true" as a float (issue #516)

This commit is contained in:
Benoit Blanchon
2017-06-03 16:22:26 +02:00
parent 98413089f6
commit bff77abe6a
6 changed files with 26 additions and 8 deletions

View File

@ -61,8 +61,6 @@ inline T JsonVariant::variantAsInteger() const {
return T(~_content.asInteger + 1);
case JSON_STRING:
case JSON_UNPARSED:
if (!_content.asString) return 0;
if (!strcmp("true", _content.asString)) return 1;
return Polyfills::parseInteger<T>(_content.asString);
default:
return T(_content.asFloat);

View File

@ -20,7 +20,7 @@ inline T parseFloat(const char* s) {
typedef typename traits::mantissa_type mantissa_t;
typedef typename traits::exponent_type exponent_t;
if (!s) return 0;
if (!s) return 0; // NULL
bool negative_result = false;
switch (*s) {
@ -30,6 +30,7 @@ inline T parseFloat(const char* s) {
s++;
}
if (*s == 't') return 1; // true
if (*s == 'n' || *s == 'N') return traits::nan();
if (*s == 'i' || *s == 'I')
return negative_result ? -traits::inf() : traits::inf();

View File

@ -16,7 +16,9 @@ namespace ArduinoJson {
namespace Polyfills {
template <typename T>
T parseInteger(const char *s) {
if (!s) return 0;
if (!s) return 0; // NULL
if (*s == 't') return 1; // "true"
T result = 0;
bool negative_result = false;