From 1bb8eb33dd19a8f9feab5dd585defb9983510f65 Mon Sep 17 00:00:00 2001 From: Bob Hiestand Date: Thu, 10 Dec 2009 15:37:48 -0600 Subject: [PATCH] Replace system() with wrapper to protect quotes in Windows. --- plugin/vcsbzr.vim | 6 +++--- plugin/vcscommand.vim | 19 ++++++++++++++++++- plugin/vcscvs.vim | 2 +- plugin/vcsgit.vim | 8 ++++---- plugin/vcshg.vim | 8 ++++---- plugin/vcssvk.vim | 4 ++-- plugin/vcssvn.vim | 2 +- 7 files changed, 33 insertions(+), 16 deletions(-) diff --git a/plugin/vcsbzr.vim b/plugin/vcsbzr.vim index a74e93b..bbbca38 100644 --- a/plugin/vcsbzr.vim +++ b/plugin/vcsbzr.vim @@ -84,7 +84,7 @@ endfunction " Function: s:bzrFunctions.Identify(buffer) {{{2 function! s:bzrFunctions.Identify(buffer) let fileName = resolve(bufname(a:buffer)) - let statusText = system(s:Executable() . ' info -- "' . fileName . '"') + let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . fileName . '"') if(v:shell_error) return 0 else @@ -169,8 +169,8 @@ endfunction function! s:bzrFunctions.GetBufferInfo() let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) let fileName = resolve(bufname(originalBuffer)) - let statusText = system(s:Executable() . ' status -S -- "' . fileName . '"') - let revision = system(s:Executable() . ' revno -- "' . fileName . '"') + let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -S -- "' . fileName . '"') + let revision = s:VCSCommandUtility.system(s:Executable() . ' revno -- "' . fileName . '"') if(v:shell_error) return [] endif diff --git a/plugin/vcscommand.vim b/plugin/vcscommand.vim index 0e5bfb5..88bc654 100644 --- a/plugin/vcscommand.vim +++ b/plugin/vcscommand.vim @@ -365,6 +365,23 @@ function! s:ReportError(error) echohl WarningMsg|echomsg 'VCSCommand: ' . a:error|echohl None endfunction +" Function s:VCSCommandUtility.system(...) {{{2 +" Replacement for system() function. This version protects the quoting in the +" command line on Windows systems. + +function! s:VCSCommandUtility.system(...) + if (has("win32") || has("win64")) && &sxq !~ '"' + let save_sxq = &sxq + set sxq=\" + endif + try + return call('system', a:000) + finally + if exists("save_sxq") + let &sxq = save_sxq + endif + endtry +endfunction " Function: s:CreateMapping(shortcut, expansion, display) {{{2 " Creates the given mapping by prepending the contents of @@ -1096,7 +1113,7 @@ function! VCSCommandDoCommand(cmd, cmdName, statusText, options) let oldCwd = VCSCommandChangeToCurrentFileDir(path) try - let output = system(fullCmd) + let output = s:VCSCommandUtility.system(fullCmd) finally call VCSCommandChdir(oldCwd) endtry diff --git a/plugin/vcscvs.vim b/plugin/vcscvs.vim index 004e20b..2e9c102 100644 --- a/plugin/vcscvs.vim +++ b/plugin/vcscvs.vim @@ -301,7 +301,7 @@ function! s:cvsFunctions.GetBufferInfo() endif let oldCwd = VCSCommandChangeToCurrentFileDir(fileName) try - let statusText=system(s:Executable() . ' status -- "' . realFileName . '"') + let statusText=s:VCSCommandUtility.system(s:Executable() . ' status -- "' . realFileName . '"') if(v:shell_error) return [] endif diff --git a/plugin/vcsgit.vim b/plugin/vcsgit.vim index 65af279..255e9ab 100644 --- a/plugin/vcsgit.vim +++ b/plugin/vcsgit.vim @@ -92,7 +92,7 @@ endfunction function! s:gitFunctions.Identify(buffer) let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(a:buffer))) try - call system(s:Executable() . ' rev-parse --is-inside-work-tree') + call s:VCSCommandUtility.system(s:Executable() . ' rev-parse --is-inside-work-tree') if(v:shell_error) return 0 else @@ -184,7 +184,7 @@ endfunction function! s:gitFunctions.GetBufferInfo() let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname('%'))) try - let branch = substitute(system(s:Executable() . ' symbolic-ref -q HEAD'), '\n$', '', '') + let branch = substitute(s:VCSCommandUtility.system(s:Executable() . ' symbolic-ref -q HEAD'), '\n$', '', '') if v:shell_error let branch = 'DETACHED' else @@ -197,7 +197,7 @@ function! s:gitFunctions.GetBufferInfo() if method != '' let method = ' --' . method endif - let tag = substitute(system(s:Executable() . ' describe' . method), '\n$', '', '') + let tag = substitute(s:VCSCommandUtility.system(s:Executable() . ' describe' . method), '\n$', '', '') if !v:shell_error call add(info, tag) break @@ -234,7 +234,7 @@ function! s:gitFunctions.Review(argList) let oldCwd = VCSCommandChangeToCurrentFileDir(resolve(bufname(VCSCommandGetOriginalBuffer('%')))) try - let prefix = system(s:Executable() . ' rev-parse --show-prefix') + let prefix = s:VCSCommandUtility.system(s:Executable() . ' rev-parse --show-prefix') finally call VCSCommandChdir(oldCwd) endtry diff --git a/plugin/vcshg.vim b/plugin/vcshg.vim index fc869df..6195deb 100644 --- a/plugin/vcshg.vim +++ b/plugin/vcshg.vim @@ -90,7 +90,7 @@ endfunction " Function: s:hgFunctions.Identify(buffer) {{{2 function! s:hgFunctions.Identify(buffer) - call system(s:Executable() . ' root') + call s:VCSCommandUtility.system(s:Executable() . ' root') if(v:shell_error) return 0 else @@ -195,7 +195,7 @@ endfunction function! s:hgFunctions.GetBufferInfo() let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) let fileName = bufname(originalBuffer) - let statusText = system(s:Executable() . ' status -- "' . fileName . '"') + let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -- "' . fileName . '"') if(v:shell_error) return [] endif @@ -205,10 +205,10 @@ function! s:hgFunctions.GetBufferInfo() return ['Unknown'] endif - let parentsText = system(s:Executable() . ' parents -- "' . fileName . '"') + let parentsText = s:VCSCommandUtility.system(s:Executable() . ' parents -- "' . fileName . '"') let [revision] = matchlist(parentsText, '^changeset:\s\+\(\S\+\)\n')[1] - let logText = system(s:Executable() . ' log -- "' . fileName . '"') + let logText = s:VCSCommandUtility.system(s:Executable() . ' log -- "' . fileName . '"') let [repository] = matchlist(logText, '^changeset:\s\+\(\S\+\)\n')[1] if revision == '' diff --git a/plugin/vcssvk.vim b/plugin/vcssvk.vim index 2724ff7..38111ff 100644 --- a/plugin/vcssvk.vim +++ b/plugin/vcssvk.vim @@ -89,7 +89,7 @@ function! s:svkFunctions.Identify(buffer) else let directoryName = fnamemodify(fileName, ':p:h') endif - let statusText = system(s:Executable() . ' info -- "' . directoryName . '"') + let statusText = s:VCSCommandUtility.system(s:Executable() . ' info -- "' . directoryName . '"') if(v:shell_error) return 0 else @@ -174,7 +174,7 @@ endfunction function! s:svkFunctions.GetBufferInfo() let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) let fileName = resolve(bufname(originalBuffer)) - let statusText = system(s:Executable() . ' status -v -- "' . fileName . '"') + let statusText = s:VCSCommandUtility.system(s:Executable() . ' status -v -- "' . fileName . '"') if(v:shell_error) return [] endif diff --git a/plugin/vcssvn.vim b/plugin/vcssvn.vim index e51ba45..da738ee 100644 --- a/plugin/vcssvn.vim +++ b/plugin/vcssvn.vim @@ -200,7 +200,7 @@ endfunction function! s:svnFunctions.GetBufferInfo() let originalBuffer = VCSCommandGetOriginalBuffer(bufnr('%')) let fileName = bufname(originalBuffer) - let statusText = system(s:Executable() . ' status --non-interactive -vu -- "' . fileName . '"') + let statusText = s:VCSCommandUtility.system(s:Executable() . ' status --non-interactive -vu -- "' . fileName . '"') if(v:shell_error) return [] endif -- 2.11.4.GIT