aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordundargoc <33953936+dundargoc@users.noreply.github.com>2022-01-03 16:00:50 +0100
committerGitHub <noreply@github.com>2022-01-03 08:00:50 -0700
commit297ff97647a6a68188390ef7808762bb5a13baa1 (patch)
tree7ab8c6d4fe3bcfa6ad88e965c57c308065b3c9b5
parent76435c0cfa8f39024a3b931276478b5007a1f421 (diff)
downloadrneovim-297ff97647a6a68188390ef7808762bb5a13baa1.tar.gz
rneovim-297ff97647a6a68188390ef7808762bb5a13baa1.tar.bz2
rneovim-297ff97647a6a68188390ef7808762bb5a13baa1.zip
fix(lua): stricter type check when calling API function (#16745)
Solves #13651 Co-authored-by: Gregory Anders <greg@gpanders.com>
-rw-r--r--src/nvim/lua/converter.c7
-rw-r--r--test/functional/lua/api_spec.lua2
2 files changed, 8 insertions, 1 deletions
diff --git a/src/nvim/lua/converter.c b/src/nvim/lua/converter.c
index b6792a5a97..8a702ddd60 100644
--- a/src/nvim/lua/converter.c
+++ b/src/nvim/lua/converter.c
@@ -1242,7 +1242,12 @@ LuaRef nlua_pop_LuaRef(lua_State *const lstate, Error *err)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT \
{ \
type ret; \
- ret = (type)lua_tonumber(lstate, -1); \
+ if (lua_type(lstate, -1) != LUA_TNUMBER) { \
+ api_set_error(err, kErrorTypeValidation, "Expected Lua number"); \
+ ret = (type)-1; \
+ } else { \
+ ret = (type)lua_tonumber(lstate, -1); \
+ } \
lua_pop(lstate, 1); \
return ret; \
}
diff --git a/test/functional/lua/api_spec.lua b/test/functional/lua/api_spec.lua
index f6038e23fe..cb37fb9a1c 100644
--- a/test/functional/lua/api_spec.lua
+++ b/test/functional/lua/api_spec.lua
@@ -183,6 +183,8 @@ describe('luaeval(vim.api.…)', function()
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 'test', 1, false)")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Number is not integral',
remove_trace(exc_exec([[call luaeval("vim.api.nvim_buf_get_lines(0, 1.5, 1, false)")]])))
+ eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected Lua number',
+ remove_trace(exc_exec([[call luaeval("vim.api.nvim_win_is_valid(nil)")]])))
eq('Vim(call):E5108: Error executing lua [string "luaeval()"]:1: Expected lua table',
remove_trace(exc_exec([[call luaeval("vim.api.nvim__id_float('test')")]])))