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

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.
This commit is contained in:
Justin M. Keyes
2023-06-28 04:51:55 -07:00
committed by GitHub
parent 42f9573e5d
commit e0453d7f57
3 changed files with 15 additions and 9 deletions

View File

@@ -393,6 +393,12 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error
VALIDATE(!is_cmd_ni(ea.cmdidx), "Command not implemented: %s", cmdname, {
goto end;
});
const char *fullname = IS_USER_CMDIDX(ea.cmdidx)
? get_user_command_name(ea.useridx, ea.cmdidx)
: get_command_name(NULL, ea.cmdidx);
VALIDATE(strncmp(fullname, cmdname, strlen(cmdname)) == 0, "Invalid command: \"%s\"", cmdname, {
goto end;
});
// Get the command flags so that we can know what type of arguments the command uses.
// Not required for a user command since `find_ex_command` already deals with it in that case.