Split the value of &shell option

Before, the value of `&shell` was being passed verbatim to `jobstart`
because no word splitting is done when the argument to `jobstart` is a
list. This would cause errors if the user's `&shell` were set to
something like `'/usr/local/bin/zsh -l'`.

This does not, however, fix another potential edge case, when the shell
command itself requires quoting (as per the example in the Neovim docs,
option E91). After doing some testing, it appears that `jobstart()` cannot
handle a quoted command, despite the recommendation in the manual (and
despite the fact that commands like `:terminal` work just fine with
double-quoted values for `&shell`). Whether this inconsistency is due to
a bug or something else, additional defensive action is probably needed.

For demonstration, try symlinking `/bin/bash` to `"./bad shell"`, and
inside Neovim setting `let &shell='"./bad shell"'. Everything works
fine, except `:call jobstart([&shell])` fails. Try various combinations
of quoting and calls to `jobstart()`, `split()`, and such: there seems
to be no way to get `jobstart()` to handle the quotes and spaces
properly without additional manipulation up-front.
This commit is contained in:
Greg Werbin
2016-04-17 19:10:24 -04:00
committed by Andy Stewart
parent 530bf68fca
commit 16e69e6571

View File

@@ -132,7 +132,7 @@ function! gitgutter#diff#run_diff(realtime, preserve_full_diff)
" Note that when `cmd` doesn't produce any output, i.e. the diff is empty, " Note that when `cmd` doesn't produce any output, i.e. the diff is empty,
" the `stdout` event is not fired on the job handler. Therefore we keep " the `stdout` event is not fired on the job handler. Therefore we keep
" track of the jobs ourselves so we can spot empty diffs. " track of the jobs ourselves so we can spot empty diffs.
let job_id = jobstart([&shell, '-c', cmd], { let job_id = jobstart(split(&shell) + ['-c', cmd], {
\ 'on_stdout': function('gitgutter#handle_diff_job'), \ 'on_stdout': function('gitgutter#handle_diff_job'),
\ 'on_stderr': function('gitgutter#handle_diff_job'), \ 'on_stderr': function('gitgutter#handle_diff_job'),
\ 'on_exit': function('gitgutter#handle_diff_job') \ 'on_exit': function('gitgutter#handle_diff_job')