mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
eval: Treat [] and [""] as any other empty string
This commit is contained in:
parent
af7ff808c7
commit
9af400f979
@ -11608,15 +11608,18 @@ static void f_json_decode(typval_T *argvars, typval_T *rettv)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tofree = s;
|
tofree = s;
|
||||||
|
if (s == NULL) {
|
||||||
|
assert(len == 0);
|
||||||
|
s = "";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
s = (char *) get_tv_string_buf_chk(&argvars[0], (char_u *) numbuf);
|
s = (char *) get_tv_string_buf_chk(&argvars[0], (char_u *) numbuf);
|
||||||
if (s) {
|
if (s) {
|
||||||
len = strlen(s);
|
len = strlen(s);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (s == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (json_decode_string(s, len, rettv) == FAIL) {
|
if (json_decode_string(s, len, rettv) == FAIL) {
|
||||||
emsgf(_("E474: Failed to parse %.*s"), (int) len, s);
|
emsgf(_("E474: Failed to parse %.*s"), (int) len, s);
|
||||||
rettv->v_type = VAR_NUMBER;
|
rettv->v_type = VAR_NUMBER;
|
||||||
|
@ -507,6 +507,10 @@ describe('json_decode() function', function()
|
|||||||
it('fails to parse empty string', function()
|
it('fails to parse empty string', function()
|
||||||
eq('Vim(call):E474: Attempt to decode a blank string',
|
eq('Vim(call):E474: Attempt to decode a blank string',
|
||||||
exc_exec('call json_decode("")'))
|
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',
|
eq('Vim(call):E474: Attempt to decode a blank string',
|
||||||
exc_exec('call json_decode(" ")'))
|
exc_exec('call json_decode(" ")'))
|
||||||
eq('Vim(call):E474: Attempt to decode a blank string',
|
eq('Vim(call):E474: Attempt to decode a blank string',
|
||||||
|
Loading…
Reference in New Issue
Block a user