From 3442e58c8b2dfadd1bc53445ce3c4cf198ce3f0d Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 14 Jun 2017 11:05:49 +0100 Subject: [PATCH] Simplify the code for escaping strings for Windows --- autoload/ale.vim | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/autoload/ale.vim b/autoload/ale.vim index 9147b3a..9c4be7d 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)