motiejus/dotfiles

Unnamed repository; edit this file 'description' to name the repository.
git clone https://git.jakstys.lt/motiejus/dotfiles.git
Log | Tree | Refs | README | LICENSE

commit 6c19f1ddfb74b3b21f3d1e830bee1d1ed6a72ece (tree)
parent a44310448902cb3194b1a94d30e38538aa07d957
Author: Tim Pope <code@tpope.net>
Date:   Wed,  2 Feb 2022 11:53:01 -0500

More robut escaping of +cmd arguments

Resolves: https://github.com/tpope/vim-fugitive/issues/1938

Diffstat:
Mautoload/fugitive.vim | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim @@ -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)