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