diff options
author | ZyX <kp-pav@yandex.ru> | 2016-03-20 20:03:12 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-04-18 02:48:20 +0300 |
commit | 9af400f97916851ecd86975118faea2a8c68598f (patch) | |
tree | f3615d14e90dc30decade68014c95cf74ca260ea | |
parent | af7ff808c73110f04aadaaab72eac6307dae0cc2 (diff) | |
download | rneovim-9af400f97916851ecd86975118faea2a8c68598f.tar.gz rneovim-9af400f97916851ecd86975118faea2a8c68598f.tar.bz2 rneovim-9af400f97916851ecd86975118faea2a8c68598f.zip |
eval: Treat [] and [""] as any other empty string
-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")')) |