diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-01-12 14:24:27 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-01-12 14:24:27 +0100 |
commit | 5f6b379ff3e34297d171635933f907ec80ed4f05 (patch) | |
tree | 3db4bfd51041f31d5920e723fcacb4dfc81dc2ba /src/json.c | |
parent | ec9d3001cf6fb4ffe142d34762c774e0066de6bb (diff) |
patch 8.1.0731: JS encoding does not handle negative infinityv8.1.0731
Problem: JS encoding does not handle negative infinity.
Solution: Add support for negative infinity for JS encoding. (Dominique
Pelle, closes #3792)
Diffstat (limited to 'src/json.c')
-rw-r--r-- | src/json.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/json.c b/src/json.c index 60637714a8..d9da10d359 100644 --- a/src/json.c +++ b/src/json.c @@ -316,7 +316,12 @@ json_encode_item(garray_T *gap, typval_T *val, int copyID, int options) if (isnan(val->vval.v_float)) ga_concat(gap, (char_u *)"NaN"); else if (isinf(val->vval.v_float)) - ga_concat(gap, (char_u *)"Infinity"); + { + if (val->vval.v_float < 0.0) + ga_concat(gap, (char_u *)"-Infinity"); + else + ga_concat(gap, (char_u *)"Infinity"); + } else # endif { @@ -736,7 +741,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options) break; default: - if (VIM_ISDIGIT(*p) || *p == '-') + if (VIM_ISDIGIT(*p) || (*p == '-' && VIM_ISDIGIT(p[1]))) { #ifdef FEAT_FLOAT char_u *sp = p; @@ -834,6 +839,17 @@ json_decode_item(js_read_T *reader, typval_T *res, int options) retval = OK; break; } + if (STRNICMP((char *)p, "-Infinity", 9) == 0) + { + reader->js_used += 9; + if (cur_item != NULL) + { + cur_item->v_type = VAR_FLOAT; + cur_item->vval.v_float = -INFINITY; + } + retval = OK; + break; + } if (STRNICMP((char *)p, "Infinity", 8) == 0) { reader->js_used += 8; @@ -851,6 +867,7 @@ json_decode_item(js_read_T *reader, typval_T *res, int options) if ( (len < 5 && STRNICMP((char *)p, "false", len) == 0) #ifdef FEAT_FLOAT + || (len < 9 && STRNICMP((char *)p, "-Infinity", len) == 0) || (len < 8 && STRNICMP((char *)p, "Infinity", len) == 0) || (len < 3 && STRNICMP((char *)p, "NaN", len) == 0) #endif @@ -1072,7 +1089,7 @@ json_decode(js_read_T *reader, typval_T *res, int options) * Return FAIL if the message has a decoding error. * Return MAYBE if the message is truncated, need to read more. * This only works reliable if the message contains an object, array or - * string. A number might be trucated without knowing. + * string. A number might be truncated without knowing. * Does not advance the reader. */ int |