fix(api): avoid error when parsing invalid expr after :echo (#38695)

Problem:  Parsing :echo followed by invalid expression leads to error.
Solution: Suppress error when skipping over expression.
This commit is contained in:
zeertzjq
2026-04-02 07:05:47 +08:00
committed by GitHub
parent 0851ac2706
commit f2cdf73afc
2 changed files with 12 additions and 0 deletions

View File

@@ -1640,7 +1640,9 @@ bool parse_cmdline(char **cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, const ch
char *arg = eap->arg;
while (*arg != NUL && *arg != '|' && *arg != '\n') {
char *start = arg;
emsg_skip++;
skip_expr(&arg, NULL);
emsg_skip--;
// If skip_expr didn't advance, move forward to avoid infinite loop
if (arg == start) {
arg++;

View File

@@ -4828,6 +4828,16 @@ describe('API', function()
eq('execute', result.cmd)
eq('edit foo', result.nextcmd)
end)
it('parses expr-arg commands with invalid expr #38689', function()
for _, arg in ipairs({ '&', '[', '{', '"', "'" }) do
local result = api.nvim_parse_cmd('echo ' .. arg, {})
eq({ arg }, result.args)
eq('echo', result.cmd)
eq('', result.nextcmd)
end
-- v:errmsg shouldn't be set
eq('', api.nvim_get_vvar('errmsg'))
end)
it('parses :map commands with space in RHS', function()
eq({
addr = 'none',