mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-12 21:33:53 -05:00
More robut escaping of +cmd arguments
Resolves: https://github.com/tpope/vim-fugitive/issues/1938
This commit is contained in:
@@ -5905,18 +5905,22 @@ function! s:ArgSplit(string) abort
|
||||
let arg = matchstr(string, '^\s*\%(\\.\|[^[:space:]]\)\+')
|
||||
let string = strpart(string, len(arg))
|
||||
let arg = substitute(arg, '^\s\+', '', '')
|
||||
call add(args, substitute(arg, '\\\@<!\\ ', ' ', 'g'))
|
||||
call add(args, substitute(arg, '\\\+[|" ]', '\=submatch(0)[len(submatch(0))/2 : -1]', 'g'))
|
||||
endwhile
|
||||
return args
|
||||
endfunction
|
||||
|
||||
function! s:PlusEscape(string) abort
|
||||
return substitute(a:string, '\\*[|" ]', '\=repeat("\\", len(submatch(0))).submatch(0)', 'g')
|
||||
endfunction
|
||||
|
||||
function! s:OpenParse(string, wants_cmd) abort
|
||||
let opts = []
|
||||
let cmds = []
|
||||
let args = s:ArgSplit(a:string)
|
||||
while !empty(args)
|
||||
if args[0] =~# '^++'
|
||||
call add(opts, ' ' . escape(remove(args, 0), ' |"'))
|
||||
call add(opts, ' ' . s:PlusEscape(remove(args, 0)))
|
||||
elseif a:wants_cmd && args[0] =~# '^+'
|
||||
call add(cmds, remove(args, 0)[1:-1])
|
||||
else
|
||||
@@ -5983,9 +5987,9 @@ function! s:OpenParse(string, wants_cmd) abort
|
||||
|
||||
let pre = join(opts, '')
|
||||
if len(cmds) > 1
|
||||
let pre .= ' +' . escape(join(map(cmds, '"exe ".string(v:val)'), '|'), ' |"')
|
||||
let pre .= ' +' . s:PlusEscape(join(map(cmds, '"exe ".string(v:val)'), '|'))
|
||||
elseif len(cmds)
|
||||
let pre .= ' +' . escape(cmds[0], ' |"')
|
||||
let pre .= ' +' . s:PlusEscape(cmds[0])
|
||||
endif
|
||||
return [url, pre]
|
||||
endfunction
|
||||
@@ -7905,7 +7909,7 @@ function! s:GF(mode) abort
|
||||
endtry
|
||||
if len(results) > 1
|
||||
let cmd = 'G' . a:mode .
|
||||
\ (empty(results[1]) ? '' : ' +' . escape(results[1], ' |')) . ' ' .
|
||||
\ (empty(results[1]) ? '' : ' +' . s:PlusEscape(results[1])) . ' ' .
|
||||
\ fnameescape(results[0])
|
||||
let tail = join(map(results[2:-1], '"|" . v:val'), '')
|
||||
if a:mode ==# 'pedit' && len(tail)
|
||||
|
||||
Reference in New Issue
Block a user