summaryrefslogtreecommitdiffstats
path: root/plugin
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-05-01 10:02:26 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2024-05-01 10:02:26 +0900
commit835d2fb98cedbb6384dfbeb41e4ba48c3c0a8081 (patch)
tree7fcab6b5dc72ef21e578ea5090bf416a8ae5a416 /plugin
parenta9811addaa67b8fd73a0b1a4c544b7441d629635 (diff)
[vim] Fix argument escaping for Windows batch file
Fix #3620
Diffstat (limited to 'plugin')
-rw-r--r--plugin/fzf.vim26
1 files changed, 21 insertions, 5 deletions
diff --git a/plugin/fzf.vim b/plugin/fzf.vim
index a99dbb2b..4a1ca0e5 100644
--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -83,12 +83,28 @@ else
endfunction
endif
+let s:cmd_control_chars = ['&', '|', '<', '>', '(', ')', '@', '^', '!']
+
function! s:shellesc_cmd(arg)
- let escaped = substitute(a:arg, '[&|<>()@^]', '^&', 'g')
- let escaped = substitute(escaped, '%', '%%', 'g')
- let escaped = substitute(escaped, '"', '\\^&', 'g')
- let escaped = substitute(escaped, '\(\\\+\)\(\\^\)', '\1\1\2', 'g')
- return '^"'.substitute(escaped, '\(\\\+\)$', '\1\1', '').'^"'
+ let e = '"'
+ let slashes = 0
+ for c in split(a:arg, '\zs')
+ if c ==# '\'
+ let slashes += 1
+ elseif c ==# '"'
+ let e .= repeat('\', slashes + 1)
+ let slashes = 0
+ elseif c ==# '%'
+ let e .= '%'
+ elseif index(s:cmd_control_chars, c) >= 0
+ let e .= '^'
+ else
+ let slashes = 0
+ endif
+ let e .= c
+ endfor
+ let e .= repeat('\', slashes) .'"'
+ return e
endfunction
function! fzf#shellescape(arg, ...)