From b68ca08fe333095fcc15a7933907ff273c125590 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 29 Jun 2006 22:50:35 +0000 Subject: [PATCH] Better command escaping on Windows; hacks for SQL Server with dbext --- plugin/rails.vim | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/plugin/rails.vim b/plugin/rails.vim index 1ce18618..e066823e 100644 --- a/plugin/rails.vim +++ b/plugin/rails.vim @@ -36,6 +36,8 @@ function! s:rquote(str) " Imperfect but adequate for Ruby arguments if a:str =~ '^[A-Za-z0-9_/.-]\+$' return a:str + elseif &shell =~? 'cmd' + return '"'.s:gsub(s:gsub(a:str,'\','\\'),'"','\\"').'"' else return "'".s:gsub(s:gsub(a:str,'\','\\'),"'","'\\\\''")."'" endif @@ -54,7 +56,7 @@ function! s:rubyexestr(cmd) endfunction function! s:rubyexe(cmd) - exe "!".s:rubyexestr(a:cmd) + exe "!".s:gsub(s:rubyexestr(a:cmd),'[!%$]','\\&') return v:shell_error endfunction @@ -67,14 +69,10 @@ function! s:rubyeval(ruby,...) if !executable("ruby") return def endif - "if &shellquote == "" - "let q = '"' - "else - "let q = &shellquote - "endif let cmd = s:rubyexestr('-e '.s:rquote('require %{rubygems} rescue nil; require %{active_support} rescue nil; '.a:ruby)) "let g:rails_last_ruby_command = cmd - let results = system(cmd) + " If the shell is messed up, this command could cause an error message + silent! let results = system(cmd) "let g:rails_last_ruby_result = results if results =~ '-e:\d' return def @@ -157,6 +155,8 @@ endfunction " }}}1 " "Public" Interface {{{1 +" RailsRoot() is the only official public function + function! RailsRoot() if exists("b:rails_root") return b:rails_root @@ -387,8 +387,7 @@ function! s:BufCommands() command! -buffer -bar -complete=custom,s:FindList -nargs=* -count=1 Rvsfind :call s:Find(0,,"vert s",) command! -buffer -bar -complete=custom,s:FindList -nargs=* -count=1 Rvsplitfind :call s:Find(0,,"vert s",) command! -buffer -bar -complete=custom,s:FindList -nargs=* -count=1 Rtabfind :call s:Find(0,,"tab",) - command! -buffer -bar -nargs=0 Alternate :echoerr Use :A instead - command! -buffer -bar -nargs=0 Ralternate :call s:Alternate(0,"find") + command! -buffer -bar -nargs=0 Ralternate :call s:warn('Use :A instead')|call s:Alternate(0,"find") if g:rails_avim_commands command! -buffer -bar -nargs=0 A :call s:Alternate(0,"find") command! -buffer -bar -nargs=0 AS :call s:Alternate(0,"sfind") @@ -1109,7 +1108,7 @@ function! RailsBalloonexpr() if str !~ '^\u' return "" endif - let res = s:sub(system("ri ".s:rquote(str)),'\n$','') + silent! let res = s:sub(system("ri ".s:rquote(str)),'\n$','') if res =~ '^Nothing known about' return '' endif @@ -1606,11 +1605,14 @@ function! s:BufDatabase(...) " Crude caching mechanism if s:dbext_last_root != RailsRoot() if exists("g:loaded_dbext") && (g:rails_dbext || (a:0 && a:1)) + " Ideally we would filter this through ERB but that could be insecure. + " It might be possible to make use of taint checking. let cmdb = 'require %{yaml}; y = File.open(%q{'.RailsRoot().'/config/database.yml}) {|f| YAML::load(f)}; e = y[%{' let cmde = '}]; i=0; e=y[e] while e.respond_to?(:to_str) && (i+=1)<16; e.each{|k,v|puts k+%{=}+v if v}' let out = s:rubyeval(cmdb.env.cmde,'') let adapter = s:extractdbarg(out,'adapter') - let s:sbext_bin = '' + let s:dbext_bin = '' + let s:dbext_integratedlogin = '' if adapter == 'postgresql' let adapter = 'pgsql' elseif adapter == 'sqlite3' @@ -1635,6 +1637,12 @@ function! s:BufDatabase(...) let s:dbext_host = s:extractdbarg(out,'host') let s:dbext_port = s:extractdbarg(out,'port') let s:dbext_dsnname = s:extractdbarg(out,'dsn') + if s:dbext_host =~? '^\cDBI:' + if s:dbext_host =~? '\c\' + let s:dbext_integratedlogin = 1 + endif + let s:dbext_host = matchstr(s:dbext_host,'\c\<\%(Server\|Data Source\)\s*=\s*\zs[^;]*') + endif let s:dbext_last_root = RailsRoot() endif endif @@ -1648,6 +1656,7 @@ function! s:BufDatabase(...) silent! let b:dbext_host = s:dbext_host silent! let b:dbext_port = s:dbext_port silent! let b:dbext_dsnname = s:dbext_dsnname + silent! let b:dbext_integratedlogin = s:dbext_integratedlogin endif endfunction