1
0
forked from aniani/vim

patch 7.4.1430

Problem:    When encoding JSON, turning NaN and Infinity into null without
            giving an error is not useful.
Solution:   Pass NaN and Infinity on.  If the receiver can't handle them it
            will generate the error.
This commit is contained in:
Bram Moolenaar
2016-02-27 16:33:22 +01:00
parent d804fdf4c2
commit 7ce686c990
4 changed files with 19 additions and 21 deletions

View File

@@ -27,8 +27,10 @@
# define isnan(x) _isnan(x)
# define isinf(x) (!_finite(x) && !_isnan(x))
# endif
# if defined(_MSC_VER) && !defined(INFINITY)
# if !defined(INFINITY) && defined(DBL_MAX)
# define INFINITY (DBL_MAX+DBL_MAX)
# endif
# if !defined(NAN) && defined(INFINITY)
# define NAN (INFINITY-INFINITY)
# endif
#endif
@@ -285,12 +287,10 @@ json_encode_item(garray_T *gap, typval_T *val, int copyID, int options)
case VAR_FLOAT:
#ifdef FEAT_FLOAT
# if defined(HAVE_MATH_H)
if ((options & JSON_JS) && isnan(val->vval.v_float))
if (isnan(val->vval.v_float))
ga_concat(gap, (char_u *)"NaN");
else if ((options & JSON_JS) && isinf(val->vval.v_float))
else if (isinf(val->vval.v_float))
ga_concat(gap, (char_u *)"Infinity");
else if (isnan(val->vval.v_float) || isinf(val->vval.v_float))
ga_concat(gap, (char_u *)"null");
else
# endif
{