diff options
-rw-r--r-- | src/nvim/eval.c | 9 | ||||
-rw-r--r-- | test/functional/eval/json_functions_spec.lua | 4 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index bec234bb22..e23702ac16 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -11608,15 +11608,18 @@ static void f_json_decode(typval_T *argvars, typval_T *rettv) return; } tofree = s; + if (s == NULL) { + assert(len == 0); + s = ""; + } } else { s = (char *) get_tv_string_buf_chk(&argvars[0], (char_u *) numbuf); if (s) { len = strlen(s); + } else { + return; } } - if (s == NULL) { - return; - } if (json_decode_string(s, len, rettv) == FAIL) { emsgf(_("E474: Failed to parse %.*s"), (int) len, s); rettv->v_type = VAR_NUMBER; diff --git a/test/functional/eval/json_functions_spec.lua b/test/functional/eval/json_functions_spec.lua index 091b6f5457..0b1862fa8b 100644 --- a/test/functional/eval/json_functions_spec.lua +++ b/test/functional/eval/json_functions_spec.lua @@ -508,6 +508,10 @@ describe('json_decode() function', function() eq('Vim(call):E474: Attempt to decode a blank string', exc_exec('call json_decode("")')) eq('Vim(call):E474: Attempt to decode a blank string', + exc_exec('call json_decode([])')) + eq('Vim(call):E474: Attempt to decode a blank string', + exc_exec('call json_decode([""])')) + eq('Vim(call):E474: Attempt to decode a blank string', exc_exec('call json_decode(" ")')) eq('Vim(call):E474: Attempt to decode a blank string', exc_exec('call json_decode("\\t")')) |