Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #374 shellescape problem #380

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions autoload/vundle/installer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func! vundle#installer#delete(bang, dir_name) abort
\ 'rm -rf'

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)

Expand Down Expand Up @@ -214,15 +214,15 @@ func! s:sync(bang, bundle) abort
let git_dir = expand(a:bundle.path().'/.git/', 1)
if isdirectory(git_dir) || filereadable(expand(a:bundle.path().'/.git', 1))
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 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 initial_sha = s:system(get_current_sha)[0:15]
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 = ''
endif

Expand Down Expand Up @@ -250,19 +250,16 @@ func! s:sync(bang, bundle) abort
return 'updated'
endf

func! g:shellesc(cmd) abort
func! vundle#installer#shellesc(cmd) abort
if ((has('win32') || has('win64')) && empty(matchstr(&shell, 'sh')))
if &shellxquote != '(' " workaround for patch #445
return '"'.a:cmd.'"' " enclose in quotes so && joined cmds work
endif
return '"' . substitute(a:cmd, '"', '\\"', 'g') . '"'
endif
return a:cmd
return shellescape(a:cmd)
endf

func! g:shellesc_cd(cmd) abort
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 = g:shellesc(cmd)
return cmd
else
return a:cmd
Expand Down
10 changes: 5 additions & 5 deletions autoload/vundle/scripts.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func! s:create_changelog() abort
let updated_sha = bundle_data[1]
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 '.
\ initial_sha.'..'.updated_sha

Expand Down Expand Up @@ -155,13 +155,13 @@ func! s:fetch_scripts(to)

let l:vim_scripts_json = 'http://vim-scripts.org/api/scripts.json'
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")
let temp = shellescape(tempname())
let cmd = 'wget -q -O '.temp.' '.l:vim_scripts_json. ' && mv -f '.temp.' '.shellescape(a:to)
let temp = vundle#installer#shellesc(tempname())
let cmd = 'wget -q -O '.temp.' '.l:vim_scripts_json. ' && mv -f '.temp.' '.vundle#installer#shellesc(a:to)
if (has('win32') || has('win64'))
let cmd = substitute(cmd, 'mv -f ', 'move /Y ', '') " change force flag
let cmd = g:shellesc(cmd)
let cmd = vundle#installer#shellesc(cmd)
end
else
echoerr 'Error curl or wget is not available!'
Expand Down
13 changes: 6 additions & 7 deletions test/vimrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ set nocompatible
set nowrap

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'

" Vundle Options
" let g:vundle_default_git_proto = 'git'

if !isdirectory(expand(root, 1).'/vundle')
exec '!git clone '.src.' '.shellescape(root, 1).'/vundle'
endif
" if !isdirectory(expand(root, 1).'/vundle')
" exec '!git clone '.src.' '.shellescape(root, 1).'/vundle'
" endif

filetype off
syntax on

runtime macros/matchit.vim

exec 'set rtp+='.root.'/vundle'
" This test should be executed in "test" directory
set rtp+=..

call vundle#rc(root)

Bundle "gmarik/vundle"

" vim-scripts name
Bundle 'molokai'

Expand Down