commit 130cb4815a5c6625a938b1e93a7d60d7a38ad8dd
parent 0bbe8e7fc257bd06a857bfc762c2b1e8e84463e1
Author: zeertzjq <zeertzjq@outlook.com>
Date: Fri, 1 Dec 2023 13:56:04 +0800
fix(api): use a conditional stack for nvim_cmd (#26341)
Diffstat:
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
@@ -1711,6 +1711,9 @@ int execute_cmd(exarg_T *eap, CmdParseInfo *cmdinfo, bool preview)
goto end;
}
+ cstack_T cstack = { .cs_idx = -1 };
+ eap->cstack = &cstack;
+
// Execute the command
execute_cmd0(&retv, eap, &errormsg, preview);
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
@@ -4547,5 +4547,24 @@ describe('API', function()
ok(luv.now() - start <= 300)
end)
end)
+ it(':call with unknown function does not crash #26289', function()
+ eq('Vim:E117: Unknown function: UnknownFunc',
+ pcall_err(meths.cmd, {cmd = 'call', args = {'UnknownFunc()'}}, {}))
+ end)
+ it(':throw does not crash #24556', function()
+ eq('42', pcall_err(meths.cmd, {cmd = 'throw', args = {'42'}}, {}))
+ end)
+ it('can use :return #24556', function()
+ exec([[
+ func Foo()
+ let g:pos = 'before'
+ call nvim_cmd({'cmd': 'return', 'args': ['[1, 2, 3]']}, {})
+ let g:pos = 'after'
+ endfunc
+ let g:result = Foo()
+ ]])
+ eq('before', meths.get_var('pos'))
+ eq({1, 2, 3}, meths.get_var('result'))
+ end)
end)
end)