summaryrefslogtreecommitdiff
path: root/autoload/ale.vim
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-06-14 11:05:49 +0100
committerw0rp <devw0rp@gmail.com>2017-06-14 11:05:49 +0100
commit3442e58c8b2dfadd1bc53445ce3c4cf198ce3f0d (patch)
treedbbce259dd1459a9570d59a75ee33440b0673ea7 /autoload/ale.vim
parentf472e04b095565e843490752c0170d32d3ba3ccb (diff)
downloadale-3442e58c8b2dfadd1bc53445ce3c4cf198ce3f0d.zip
Simplify the code for escaping strings for Windows
Diffstat (limited to 'autoload/ale.vim')
-rw-r--r--autoload/ale.vim25
1 files changed, 10 insertions, 15 deletions
diff --git a/autoload/ale.vim b/autoload/ale.vim
index 9147b3a5..9c4be7d2 100644
--- a/autoload/ale.vim
+++ b/autoload/ale.vim
@@ -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)