[Backport release-0.9] fix(api): nvim_cmd{cmd="win_getid"} parsed as :winsize (#24189)

fix(api): nvim_cmd{cmd="win_getid"} parsed as :winsize

Problem:
`:lua vim.cmd.win_getid(30,10)` is interpreted as `:win[size] 30 10`.
User intention was to call `vim.fn.win_getid(30,10)`.

Solution:
Check that the `cmd` actually matches the resolved command.

(cherry picked from commit 629f8d1e46)

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
github-actions[bot]
2023-06-28 05:34:55 -07:00
committed by GitHub
parent 213a5204ee
commit c8bd1d131f
3 changed files with 15 additions and 9 deletions

View File

@@ -335,8 +335,7 @@ describe('API', function()
nvim('command', 'edit '..fname)
nvim('command', 'normal itesting\napi')
nvim('command', 'w')
local f = io.open(fname)
ok(f ~= nil)
local f = assert(io.open(fname))
if is_os('win') then
eq('testing\r\napi\r\n', f:read('*a'))
else
@@ -3948,7 +3947,7 @@ describe('API', function()
}
}, meths.parse_cmd('MyCommand test it', {}))
end)
it('errors for invalid command', function()
it('validates command', function()
eq('Error while parsing command line', pcall_err(meths.parse_cmd, '', {}))
eq('Error while parsing command line', pcall_err(meths.parse_cmd, '" foo', {}))
eq('Error while parsing command line: E492: Not an editor command: Fubar',
@@ -4095,6 +4094,11 @@ describe('API', function()
eq("Invalid 'reg': expected single character, got xx",
pcall_err(meths.cmd, { cmd = "put", args = {}, reg = 'xx' }, {}))
-- #20681
eq('Invalid command: "win_getid"', pcall_err(meths.cmd, { cmd = 'win_getid'}, {}))
eq('Invalid command: "echo "hi""', pcall_err(meths.cmd, { cmd = 'echo "hi"'}, {}))
eq('Invalid command: "win_getid"', pcall_err(exec_lua, [[return vim.cmd.win_getid{}]]))
-- Lua call allows empty {} for dict item.
eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, magic = {} }]]))
eq('', exec_lua([[return vim.cmd{ cmd = "set", args = {}, mods = {} }]]))