mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.1.0731: JS encoding does not handle negative infinity
Problem: JS encoding does not handle negative infinity. Solution: Add support for negative infinity for JS encoding. (Dominique Pelle, closes #3792)
This commit is contained in:
23
src/json.c
23
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
|
||||
|
Reference in New Issue
Block a user