summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-05-26 00:06:16 +0100
committerw0rp <devw0rp@gmail.com>2017-05-26 00:06:16 +0100
commitc89587785b6fc4cba844b7eda2dbd65d15185374 (patch)
tree649598602e229086e9eba8a37790216a115af393 /autoload
parentfb07971290783e1a71e8306e760e1fd645873277 (diff)
downloadale-c89587785b6fc4cba844b7eda2dbd65d15185374.zip
Fix #549 - escape strings more appropriately for use with cmd /c
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale.vim22
1 files changed, 17 insertions, 5 deletions
diff --git a/autoload/ale.vim b/autoload/ale.vim
index d8db3bfd..066bfa07 100644
--- a/autoload/ale.vim
+++ b/autoload/ale.vim
@@ -135,14 +135,26 @@ 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'
- " FIXME: Fix shell escaping for Windows.
- return fnameescape(a:str)
- else
- " An extra space is used here to disable the custom-checks.
- return shellescape (a:str)
+ 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'))
endif
+
+ return shellescape (a:str)
endfunction