From 8705a95d9babfc3acafeb28babfff021fce5782d Mon Sep 17 00:00:00 2001 From: Qiming zhao Date: Thu, 2 Nov 2017 12:04:31 +0800 Subject: Add shellescape for file path --- autoload/prettier.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/prettier.vim b/autoload/prettier.vim index 783e527..35935db 100644 --- a/autoload/prettier.vim +++ b/autoload/prettier.vim @@ -256,7 +256,7 @@ function! s:Get_Prettier_Exec_Args(config) abort \ ' --config-precedence ' . \ get(a:config, 'configPrecedence', g:prettier#config#config_precedence) . \ ' --stdin-filepath ' . - \ simplify(expand("%:p")) . + \ shellescape(simplify(expand("%:p"))) . \ ' --stdin ' return l:cmd endfunction -- cgit v1.3 From e386a3a991e8b1ac7f97082996bd9626d1e7beb9 Mon Sep 17 00:00:00 2001 From: Qiming zhao Date: Thu, 2 Nov 2017 13:16:15 +0800 Subject: Borrow escape code form ale.vim --- autoload/prettier.vim | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/autoload/prettier.vim b/autoload/prettier.vim index 35935db..d929ff8 100644 --- a/autoload/prettier.vim +++ b/autoload/prettier.vim @@ -256,7 +256,7 @@ function! s:Get_Prettier_Exec_Args(config) abort \ ' --config-precedence ' . \ get(a:config, 'configPrecedence', g:prettier#config#config_precedence) . \ ' --stdin-filepath ' . - \ shellescape(simplify(expand("%:p"))) . + \ prettier#Escape(simplify(expand("%:p"))) . \ ' --stdin ' return l:cmd endfunction @@ -355,3 +355,21 @@ endfunction function! s:Suggest_Install_Prettier() abort echohl WarningMsg | echom 'Prettier: no prettier executable installation found.' | echohl NONE endfunction + +" Borrowed from https://github.com/w0rp/ale/blob/master/autoload/ale.vim +function! prettier#Escape(str) abort + if fnamemodify(&shell, ':t') is? 'cmd.exe' + " 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) +endfunction -- cgit v1.3