fix(health): do not run external processes in a shell

This commit is contained in:
zeertzjq 2022-02-03 17:19:51 +08:00
parent 21cdecc8e0
commit a87ecf5d08
3 changed files with 26 additions and 15 deletions

View File

@ -148,14 +148,14 @@ endfunction
function! s:get_tmux_option(option) abort
let cmd = 'tmux show-option -qvg '.a:option " try global scope
let out = system(cmd)
let out = system(split(cmd))
let val = substitute(out, '\v(\s|\r|\n)', '', 'g')
if v:shell_error
call health#report_error('command failed: '.cmd."\n".out)
return 'error'
elseif empty(val)
let cmd = 'tmux show-option -qvgs '.a:option " try session scope
let out = system(cmd)
let out = system(split(cmd))
let val = substitute(out, '\v(\s|\r|\n)', '', 'g')
if v:shell_error
call health#report_error('command failed: '.cmd."\n".out)
@ -202,11 +202,11 @@ function! s:check_tmux() abort
" check default-terminal and $TERM
call health#report_info('$TERM: '.$TERM)
let cmd = 'tmux show-option -qvg default-terminal'
let out = system(cmd)
let out = system(split(cmd))
let tmux_default_term = substitute(out, '\v(\s|\r|\n)', '', 'g')
if empty(tmux_default_term)
let cmd = 'tmux show-option -qvgs default-terminal'
let out = system(cmd)
let out = system(split(cmd))
let tmux_default_term = substitute(out, '\v(\s|\r|\n)', '', 'g')
endif
@ -225,7 +225,7 @@ function! s:check_tmux() abort
endif
" check for RGB capabilities
let info = system('tmux server-info')
let info = system(['tmux', 'server-info'])
let has_tc = stridx(info, " Tc: (flag) true") != -1
let has_rgb = stridx(info, " RGB: (flag) true") != -1
if !has_tc && !has_rgb
@ -242,7 +242,7 @@ function! s:check_terminal() abort
endif
call health#report_start('terminal')
let cmd = 'infocmp -L'
let out = system(cmd)
let out = system(split(cmd))
let kbs_entry = matchstr(out, 'key_backspace=[^,[:space:]]*')
let kdch1_entry = matchstr(out, 'key_dc=[^,[:space:]]*')

View File

@ -565,7 +565,7 @@ function! s:check_ruby() abort
\ ['Install Ruby and verify that `ruby` and `gem` commands work.'])
return
endif
call health#report_info('Ruby: '. s:system('ruby -v'))
call health#report_info('Ruby: '. s:system(['ruby', '-v']))
let [host, err] = provider#ruby#Detect()
if empty(host)
@ -588,11 +588,11 @@ function! s:check_ruby() abort
endif
let latest_gem = get(split(latest_gem, 'neovim (\|, \|)$' ), 0, 'not found')
let current_gem_cmd = host .' --version'
let current_gem_cmd = [host, '--version']
let current_gem = s:system(current_gem_cmd)
if s:shell_error
call health#report_error('Failed to run: '. current_gem_cmd,
\ ['Report this issue with the output of: ', current_gem_cmd])
call health#report_error('Failed to run: '. join(current_gem_cmd),
\ ['Report this issue with the output of: ', join(current_gem_cmd)])
return
endif
@ -619,7 +619,7 @@ function! s:check_node() abort
\ ['Install Node.js and verify that `node` and `npm` (or `yarn`) commands work.'])
return
endif
let node_v = get(split(s:system('node -v'), "\n"), 0, '')
let node_v = get(split(s:system(['node', '-v']), "\n"), 0, '')
call health#report_info('Node.js: '. node_v)
if s:shell_error || s:version_cmp(node_v[1:], '6.0.0') < 0
call health#report_warn('Nvim node.js host does not support '.node_v)
@ -660,8 +660,8 @@ function! s:check_node() abort
let current_npm_cmd = ['node', host, '--version']
let current_npm = s:system(current_npm_cmd)
if s:shell_error
call health#report_error('Failed to run: '. string(current_npm_cmd),
\ ['Report this issue with the output of: ', string(current_npm_cmd)])
call health#report_error('Failed to run: '. join(current_npm_cmd),
\ ['Report this issue with the output of: ', join(current_npm_cmd)])
return
endif
@ -734,8 +734,8 @@ function! s:check_perl() abort
let current_cpan_cmd = [perl_exec, '-W', '-MNeovim::Ext', '-e', 'print $Neovim::Ext::VERSION']
let current_cpan = s:system(current_cpan_cmd)
if s:shell_error
call health#report_error('Failed to run: '. string(current_cpan_cmd),
\ ['Report this issue with the output of: ', string(current_cpan_cmd)])
call health#report_error('Failed to run: '. join(current_cpan_cmd),
\ ['Report this issue with the output of: ', join(current_cpan_cmd)])
return
endif

View File

@ -230,3 +230,14 @@ describe('health.vim', function()
end)
end)
end)
describe(':checkhealth provider', function()
it("works correctly with a wrongly configured 'shell'", function()
clear()
command([[set shell=echo\ WRONG!!!]])
command('let g:loaded_perl_provider = 0')
command('let g:loaded_python3_provider = 0')
command('checkhealth provider')
eq(nil, string.match(curbuf_contents(), 'WRONG!!!'))
end)
end)