forked from bblanchon/ArduinoJson
Fixed reading "true" as a float (issue #516)
This commit is contained in:
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user