Simplify the code for escaping strings for Windows
This commit is contained in:
parent
f472e04b09
commit
3442e58c8b
@ -155,25 +155,20 @@ function! ale#Set(variable_name, default) abort
|
|||||||
return l:value
|
return l:value
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:EscapePercents(str) abort
|
|
||||||
return substitute(a:str, '%', '%%', 'g')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Escape a string suitably for each platform.
|
" Escape a string suitably for each platform.
|
||||||
" shellescape does not work on Windows.
|
" shellescape does not work on Windows.
|
||||||
function! ale#Escape(str) abort
|
function! ale#Escape(str) abort
|
||||||
if fnamemodify(&shell, ':t') ==? 'cmd.exe'
|
if fnamemodify(&shell, ':t') ==? 'cmd.exe'
|
||||||
if a:str =~# '\v^[a-zA-Z0-9-_\\/:%]+$'
|
" If the string contains spaces, it will be surrounded by quotes.
|
||||||
return s:EscapePercents(a:str)
|
" Otherwise, special characters will be escaped with carets (^).
|
||||||
endif
|
return substitute(
|
||||||
|
\ a:str =~# ' '
|
||||||
if a:str =~# ' '
|
\ ? '"' . substitute(a:str, '"', '""', 'g') . '"'
|
||||||
return '"'
|
\ : substitute(a:str, '\v([&|<>^])', '^\1', 'g'),
|
||||||
\ . substitute(s:EscapePercents(a:str), '"', '""', 'g')
|
\ '%',
|
||||||
\ . '"'
|
\ '%%',
|
||||||
endif
|
\ 'g',
|
||||||
|
\)
|
||||||
return s:EscapePercents(substitute(a:str, '\v([&|<>^])', '^\1', 'g'))
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return shellescape (a:str)
|
return shellescape (a:str)
|
||||||
|
Loading…
Reference in New Issue
Block a user