From cf68f0a51202342163825015602bdf78b783c777 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 11 May 2022 22:51:53 +0600 Subject: [PATCH] fix(api): make `nvim_cmd` work correctly with empty arguments list (#18527) Closes #18526. --- src/nvim/api/private/helpers.c | 3 ++- test/functional/api/vim_spec.lua | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index ccf1896f08..542e5c4953 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1843,7 +1843,8 @@ int build_cmdline_str(char **cmdlinep, exarg_T *eap, CmdParseInfo *cmdinfo, char CMDLINE_APPEND(" %s", args[i]); } eap->argc = argc; - eap->arg = argc > 0 ? eap->args[0] : NULL; + // If there isn't an argument, make eap->arg point to end of cmd + eap->arg = argc > 0 ? eap->args[0] : cmdline + pos; // Replace, :make and :grep with 'makeprg' and 'grepprg'. char *p = replace_makeprg(eap, eap->arg, cmdlinep); diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index e07202c46f..f39aa2f20b 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3615,5 +3615,9 @@ describe('API', function() it('errors if command is not implemented', function() eq("Command not implemented: popup", pcall_err(meths.cmd, { cmd = "popup" }, {})) end) + it('works with empty arguments list', function() + meths.cmd({ cmd = "update" }, {}) + meths.cmd({ cmd = "buffer", count = 0 }, {}) + end) end) end)