mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-14 06:13:51 -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 arg = matchstr(string, '^\s*\%(\\.\|[^[:space:]]\)\+')
|
||||||
let string = strpart(string, len(arg))
|
let string = strpart(string, len(arg))
|
||||||
let arg = substitute(arg, '^\s\+', '', '')
|
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
|
endwhile
|
||||||
return args
|
return args
|
||||||
endfunction
|
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
|
function! s:OpenParse(string, wants_cmd) abort
|
||||||
let opts = []
|
let opts = []
|
||||||
let cmds = []
|
let cmds = []
|
||||||
let args = s:ArgSplit(a:string)
|
let args = s:ArgSplit(a:string)
|
||||||
while !empty(args)
|
while !empty(args)
|
||||||
if args[0] =~# '^++'
|
if args[0] =~# '^++'
|
||||||
call add(opts, ' ' . escape(remove(args, 0), ' |"'))
|
call add(opts, ' ' . s:PlusEscape(remove(args, 0)))
|
||||||
elseif a:wants_cmd && args[0] =~# '^+'
|
elseif a:wants_cmd && args[0] =~# '^+'
|
||||||
call add(cmds, remove(args, 0)[1:-1])
|
call add(cmds, remove(args, 0)[1:-1])
|
||||||
else
|
else
|
||||||
@@ -5983,9 +5987,9 @@ function! s:OpenParse(string, wants_cmd) abort
|
|||||||
|
|
||||||
let pre = join(opts, '')
|
let pre = join(opts, '')
|
||||||
if len(cmds) > 1
|
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)
|
elseif len(cmds)
|
||||||
let pre .= ' +' . escape(cmds[0], ' |"')
|
let pre .= ' +' . s:PlusEscape(cmds[0])
|
||||||
endif
|
endif
|
||||||
return [url, pre]
|
return [url, pre]
|
||||||
endfunction
|
endfunction
|
||||||
@@ -7905,7 +7909,7 @@ function! s:GF(mode) abort
|
|||||||
endtry
|
endtry
|
||||||
if len(results) > 1
|
if len(results) > 1
|
||||||
let cmd = 'G' . a:mode .
|
let cmd = 'G' . a:mode .
|
||||||
\ (empty(results[1]) ? '' : ' +' . escape(results[1], ' |')) . ' ' .
|
\ (empty(results[1]) ? '' : ' +' . s:PlusEscape(results[1])) . ' ' .
|
||||||
\ fnameescape(results[0])
|
\ fnameescape(results[0])
|
||||||
let tail = join(map(results[2:-1], '"|" . v:val'), '')
|
let tail = join(map(results[2:-1], '"|" . v:val'), '')
|
||||||
if a:mode ==# 'pedit' && len(tail)
|
if a:mode ==# 'pedit' && len(tail)
|
||||||
|
|||||||
Reference in New Issue
Block a user