Skip to content
forked from neovim/neovim

Commit

Permalink
fix: ensure has() does not change v:shell_error (neovim#18415)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0f21816)

Co-authored-by: Andrey Mishchenko <mishchea@gmail.com>
  • Loading branch information
github-actions[bot] and andmis committed May 4, 2022
1 parent 203b088 commit 1e28068
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/nvim/eval/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4278,6 +4278,8 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
"nvim",
};

// XXX: eval_has_provider() may shell out :(
const int save_shell_error = get_vim_var_nr(VV_SHELL_ERROR);
bool n = false;
const char *const name = tv_get_string(&argvars[0]);
for (size_t i = 0; i < ARRAY_SIZE(has_list); i++) {
Expand Down Expand Up @@ -4334,6 +4336,7 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
n = true;
}

set_vim_var_nr(VV_SHELL_ERROR, save_shell_error);
rettv->vval.v_number = n;
}

Expand Down
7 changes: 7 additions & 0 deletions test/functional/vimscript/has_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ describe('has()', function()
eq(0, funcs.has('wsl'))
end
end)

it('does not change v:shell_error', function()
local nvim_prog = helpers.nvim_prog
funcs.system({nvim_prog, '-es', '+73cquit'})
funcs.has('python3') -- use a call whose implementation shells out
eq(73, funcs.eval('v:shell_error'))
end)
end)

0 comments on commit 1e28068

Please sign in to comment.