mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
fix(eval): handle wrong v:lua in expr option properly (#29953)
This commit is contained in:
@ -2630,7 +2630,7 @@ static int may_call_simple_func(const char *arg, typval_T *rettv)
|
|||||||
if (parens != NULL && *skipwhite(parens + 2) == NUL) {
|
if (parens != NULL && *skipwhite(parens + 2) == NUL) {
|
||||||
if (strnequal(arg, "v:lua.", 6)) {
|
if (strnequal(arg, "v:lua.", 6)) {
|
||||||
const char *p = arg + 6;
|
const char *p = arg + 6;
|
||||||
if (skip_luafunc_name(p) == parens) {
|
if (p != parens && skip_luafunc_name(p) == parens) {
|
||||||
r = call_simple_luafunc(p, (size_t)(parens - p), rettv);
|
r = call_simple_luafunc(p, (size_t)(parens - p), rettv);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1779,6 +1779,9 @@ theend:
|
|||||||
int call_simple_luafunc(const char *funcname, size_t len, typval_T *rettv)
|
int call_simple_luafunc(const char *funcname, size_t len, typval_T *rettv)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
|
rettv->v_type = VAR_NUMBER; // default rettv is number zero
|
||||||
|
rettv->vval.v_number = 0;
|
||||||
|
|
||||||
typval_T argvars[1];
|
typval_T argvars[1];
|
||||||
argvars[0].v_type = VAR_UNKNOWN;
|
argvars[0].v_type = VAR_UNKNOWN;
|
||||||
nlua_typval_call(funcname, len, argvars, 0, rettv);
|
nlua_typval_call(funcname, len, argvars, 0, rettv);
|
||||||
|
@ -13,6 +13,7 @@ local fn = n.fn
|
|||||||
local clear = n.clear
|
local clear = n.clear
|
||||||
local eval = n.eval
|
local eval = n.eval
|
||||||
local feed = n.feed
|
local feed = n.feed
|
||||||
|
local assert_alive = n.assert_alive
|
||||||
local NIL = vim.NIL
|
local NIL = vim.NIL
|
||||||
local eq = t.eq
|
local eq = t.eq
|
||||||
|
|
||||||
@ -558,5 +559,41 @@ describe('v:lua', function()
|
|||||||
eq("Vim:E107: Missing parentheses: v:lua", pcall_err(eval, "'bad'->v:lua"))
|
eq("Vim:E107: Missing parentheses: v:lua", pcall_err(eval, "'bad'->v:lua"))
|
||||||
eq("Vim:E1085: Not a callable type: v:lua", pcall_err(eval, "'bad'->v:lua()"))
|
eq("Vim:E1085: Not a callable type: v:lua", pcall_err(eval, "'bad'->v:lua()"))
|
||||||
eq([[Vim:E15: Invalid expression: "v:lua.()"]], pcall_err(eval, "'bad'->v:lua.()"))
|
eq([[Vim:E15: Invalid expression: "v:lua.()"]], pcall_err(eval, "'bad'->v:lua.()"))
|
||||||
|
|
||||||
|
eq("Vim:E1085: Not a callable type: v:lua", pcall_err(eval, "v:lua()"))
|
||||||
|
eq([[Vim:E15: Invalid expression: "v:lua.()"]], pcall_err(eval, "v:lua.()"))
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe('invalid use in fold text', function()
|
||||||
|
before_each(function()
|
||||||
|
feed('ifoo<CR>bar<Esc>')
|
||||||
|
command('1,2fold')
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('with missing function name when used as simple function', function()
|
||||||
|
api.nvim_set_option_value('debug', 'throw', {})
|
||||||
|
eq(
|
||||||
|
[[Vim(eval):E15: Invalid expression: "v:lua.()"]],
|
||||||
|
pcall_err(command, 'set foldtext=v:lua.() | eval foldtextresult(1)')
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('with missing function name when used in expression', function()
|
||||||
|
api.nvim_set_option_value('debug', 'throw', {})
|
||||||
|
eq(
|
||||||
|
[[Vim(eval):E15: Invalid expression: "+v:lua.()"]],
|
||||||
|
pcall_err(command, 'set foldtext=+v:lua.() | eval foldtextresult(1)')
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('with non-existent function when used as simple function', function()
|
||||||
|
command('set foldtext=v:lua.NoSuchFunc() | eval foldtextresult(1)')
|
||||||
|
assert_alive()
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('with non-existent function when used in expression', function()
|
||||||
|
command('set foldtext=+v:lua.NoSuchFunc() | eval foldtextresult(1)')
|
||||||
|
assert_alive()
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user