[vim] Fix argument escaping for Windows batch file

Fix #3620
pull/3763/head
Junegunn Choi 1 month ago
parent a9811addaa
commit 835d2fb98c
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -27,6 +27,7 @@ CHANGELOG
- `change-multi(0)` - disable multi-select mode - `change-multi(0)` - disable multi-select mode
- `become` action is now supported on Windows - `become` action is now supported on Windows
- Unlike in *nix, this does not use `execve(2)`. Instead it spawns a new process and waits for it to finish, so the exact behavior may differ. - Unlike in *nix, this does not use `execve(2)`. Instead it spawns a new process and waits for it to finish, so the exact behavior may differ.
- Fixed argument escaping for Windows cmd.exe
- Bug fixes and improvements - Bug fixes and improvements
0.50.0 0.50.0

@ -83,12 +83,28 @@ else
endfunction endfunction
endif endif
let s:cmd_control_chars = ['&', '|', '<', '>', '(', ')', '@', '^', '!']
function! s:shellesc_cmd(arg) function! s:shellesc_cmd(arg)
let escaped = substitute(a:arg, '[&|<>()@^]', '^&', 'g') let e = '"'
let escaped = substitute(escaped, '%', '%%', 'g') let slashes = 0
let escaped = substitute(escaped, '"', '\\^&', 'g') for c in split(a:arg, '\zs')
let escaped = substitute(escaped, '\(\\\+\)\(\\^\)', '\1\1\2', 'g') if c ==# '\'
return '^"'.substitute(escaped, '\(\\\+\)$', '\1\1', '').'^"' 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 endfunction
function! fzf#shellescape(arg, ...) function! fzf#shellescape(arg, ...)

Loading…
Cancel
Save