Fix #374 shellescape problem

This commit is contained in:
Shougo Matsushita 2014-02-07 07:09:16 +09:00 committed by gmarik
parent a3c4c03a4c
commit 6b45d873bc
3 changed files with 18 additions and 20 deletions

View File

@ -174,7 +174,7 @@ func! vundle#installer#delete(bang, dir_name) abort
\ 'rm -rf' \ 'rm -rf'
let bundle = vundle#config#init_bundle(a:dir_name, {}) let bundle = vundle#config#init_bundle(a:dir_name, {})
let cmd .= ' '.shellescape(bundle.path()) let cmd .= ' '.vundle#installer#shellesc(bundle.path())
let out = s:system(cmd) let out = s:system(cmd)
@ -214,15 +214,15 @@ func! s:sync(bang, bundle) abort
let git_dir = expand(a:bundle.path().'/.git/', 1) let git_dir = expand(a:bundle.path().'/.git/', 1)
if isdirectory(git_dir) || filereadable(expand(a:bundle.path().'/.git', 1)) if isdirectory(git_dir) || filereadable(expand(a:bundle.path().'/.git', 1))
if !(a:bang) | return 'todate' | endif if !(a:bang) | return 'todate' | endif
let cmd = 'cd '.shellescape(a:bundle.path()).' && git pull && git submodule update --init --recursive' let cmd = 'cd '.vundle#installer#shellesc(a:bundle.path()).' && git pull && git submodule update --init --recursive'
let cmd = g:shellesc_cd(cmd) let cmd = g:shellesc_cd(cmd)
let get_current_sha = 'cd '.shellescape(a:bundle.path()).' && git rev-parse HEAD' let get_current_sha = 'cd '.vundle#installer#shellesc(a:bundle.path()).' && git rev-parse HEAD'
let get_current_sha = g:shellesc_cd(get_current_sha) let get_current_sha = g:shellesc_cd(get_current_sha)
let initial_sha = s:system(get_current_sha)[0:15] let initial_sha = s:system(get_current_sha)[0:15]
else else
let cmd = 'git clone --recursive '.shellescape(a:bundle.uri).' '.shellescape(a:bundle.path()) let cmd = 'git clone --recursive '.vundle#installer#shellesc(a:bundle.uri).' '.vundle#installer#shellesc(a:bundle.path())
let initial_sha = '' let initial_sha = ''
endif endif
@ -250,19 +250,18 @@ func! s:sync(bang, bundle) abort
return 'updated' return 'updated'
endf endf
func! g:shellesc(cmd) abort func! vundle#installer#shellesc(cmd) abort
if ((has('win32') || has('win64')) && empty(matchstr(&shell, 'sh'))) if ((has('win32') || has('win64')) && empty(matchstr(&shell, 'sh')))
if &shellxquote != '(' " workaround for patch #445 if &shellxquote != '(' " workaround for patch #445
return '"'.a:cmd.'"' " enclose in quotes so && joined cmds work return '"'.a:cmd.'"' " enclose in quotes so && joined cmds work
endif endif
endif endif
return a:cmd return shellescape(a:cmd)
endf endf
func! g:shellesc_cd(cmd) abort func! g:shellesc_cd(cmd) abort
if ((has('win32') || has('win64')) && empty(matchstr(&shell, 'sh'))) if ((has('win32') || has('win64')) && empty(matchstr(&shell, 'sh')))
let cmd = substitute(a:cmd, '^cd ','cd /d ','') " add /d switch to change drives let cmd = substitute(a:cmd, '^cd ','cd /d ','') " add /d switch to change drives
let cmd = g:shellesc(cmd)
return cmd return cmd
else else
return a:cmd return a:cmd

View File

@ -39,7 +39,7 @@ func! s:create_changelog() abort
let updated_sha = bundle_data[1] let updated_sha = bundle_data[1]
let bundle = bundle_data[2] let bundle = bundle_data[2]
let cmd = 'cd '.shellescape(bundle.path()). let cmd = 'cd '.vundle#installer#shellesc(bundle.path()).
\ ' && git log --pretty=format:"%s %an, %ar" --graph '. \ ' && git log --pretty=format:"%s %an, %ar" --graph '.
\ initial_sha.'..'.updated_sha \ initial_sha.'..'.updated_sha
@ -155,13 +155,13 @@ func! s:fetch_scripts(to)
let l:vim_scripts_json = 'http://vim-scripts.org/api/scripts.json' let l:vim_scripts_json = 'http://vim-scripts.org/api/scripts.json'
if executable("curl") if executable("curl")
let cmd = 'curl --fail -s -o '.shellescape(a:to).' '.l:vim_scripts_json let cmd = 'curl --fail -s -o '.vundle#installer#shellesc(a:to).' '.l:vim_scripts_json
elseif executable("wget") elseif executable("wget")
let temp = shellescape(tempname()) let temp = vundle#installer#shellesc(tempname())
let cmd = 'wget -q -O '.temp.' '.l:vim_scripts_json. ' && mv -f '.temp.' '.shellescape(a:to) let cmd = 'wget -q -O '.temp.' '.l:vim_scripts_json. ' && mv -f '.temp.' '.vundle#installer#shellesc(a:to)
if (has('win32') || has('win64')) if (has('win32') || has('win64'))
let cmd = substitute(cmd, 'mv -f ', 'move /Y ', '') " change force flag let cmd = substitute(cmd, 'mv -f ', 'move /Y ', '') " change force flag
let cmd = g:shellesc(cmd) let cmd = vundle#installer#shellesc(cmd)
end end
else else
echoerr 'Error curl or wget is not available!' echoerr 'Error curl or wget is not available!'

View File

@ -4,28 +4,27 @@ set nocompatible
set nowrap set nowrap
let root = '/tmp/!vundle-test/bundles/' let root = '/tmp/!vundle-test/bundles/'
let src = 'http://github.com/gmarik/vundle.git' " let src = 'http://github.com/gmarik/vundle.git'
" let src = '~/.vim/bundle/vundle/.git' " let src = '~/.vim/bundle/vundle/.git'
" Vundle Options " Vundle Options
" let g:vundle_default_git_proto = 'git' " let g:vundle_default_git_proto = 'git'
if !isdirectory(expand(root, 1).'/vundle') " if !isdirectory(expand(root, 1).'/vundle')
exec '!git clone '.src.' '.shellescape(root, 1).'/vundle' " exec '!git clone '.src.' '.shellescape(root, 1).'/vundle'
endif " endif
filetype off filetype off
syntax on syntax on
runtime macros/matchit.vim runtime macros/matchit.vim
exec 'set rtp+='.root.'/vundle' " This test should be executed in "test" directory
set rtp+=..
call vundle#rc(root) call vundle#rc(root)
Bundle "gmarik/vundle"
" vim-scripts name " vim-scripts name
Bundle 'molokai' Bundle 'molokai'