Skip to content

Commit cc9b5d8

Browse files
committed
fix escaping shell input on Windows
1 parent 9659e10 commit cc9b5d8

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

autoload/clang_format.vim

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,15 @@ endfunction
156156

157157
function! s:shellescape(str) abort
158158
if s:on_windows && (&shell =~? 'cmd\.exe')
159-
" Do not use shellescape() on Windows because it surrounds input with
160-
" single quote when 'shellslash' is on. But cmd.exe requires double
161-
" quotes. So we need to escape by ourselves.
162-
return '"' . substitute(a:str, '[&()[\]{}^=;!''+,`~]', '^\0', 'g') . '"'
159+
" shellescape() surrounds input with single quote when 'shellslash' is on. But cmd.exe
160+
" requires double quotes. Temporarily set it to 0.
161+
let shellslash = &shellslash
162+
set noshellslash
163+
try
164+
return shellescape(a:str)
165+
finally
166+
let &shellslash = shellslash
167+
endtry
163168
endif
164169
return shellescape(a:str)
165170
endfunction

0 commit comments

Comments
 (0)