summaryrefslogtreecommitdiffstats
path: root/src/json.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c23
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