fix(api): use a conditional stack for nvim_cmd (#26341)

This commit is contained in:
zeertzjq 2023-12-01 13:56:04 +08:00 committed by GitHub
parent 0bbe8e7fc2
commit 130cb4815a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -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);

View File

@ -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)