vim-patch:8.0.0625: shellescape() always escapes a newline (#8573)

Problem:    shellescape() always escapes a newline, which does not work with
            some shells. (Harm te Hennepe)
Solution:   Only escape a newline when the "special" argument is non-zero.
            (Christian Brabandt, closes vim/vim#1590)
206155280d
This commit is contained in:
Jan Edmund Lazo
2018-06-17 06:20:42 -04:00
committed by Justin M. Keyes
parent b006771cba
commit 367343ae6e
2 changed files with 28 additions and 2 deletions

View File

@@ -15066,9 +15066,10 @@ static void f_sha256(typval_T *argvars, typval_T *rettv, FunPtr fptr)
*/ */
static void f_shellescape(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_shellescape(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{ {
const bool do_special = non_zero_arg(&argvars[1]);
rettv->vval.v_string = vim_strsave_shellescape( rettv->vval.v_string = vim_strsave_shellescape(
(const char_u *)tv_get_string(&argvars[0]), non_zero_arg(&argvars[1]), (const char_u *)tv_get_string(&argvars[0]), do_special, do_special);
true);
rettv->v_type = VAR_STRING; rettv->v_type = VAR_STRING;
} }

View File

@@ -766,3 +766,28 @@ func Test_balloon_show()
call balloon_show('hi!') call balloon_show('hi!')
endif endif
endfunc endfunc
func Test_shellescape()
let save_shell = &shell
set shell=bash
call assert_equal("'text'", shellescape('text'))
call assert_equal("'te\"xt'", shellescape('te"xt'))
call assert_equal("'te'\\''xt'", shellescape("te'xt"))
call assert_equal("'te%xt'", shellescape("te%xt"))
call assert_equal("'te\\%xt'", shellescape("te%xt", 1))
call assert_equal("'te#xt'", shellescape("te#xt"))
call assert_equal("'te\\#xt'", shellescape("te#xt", 1))
call assert_equal("'te!xt'", shellescape("te!xt"))
call assert_equal("'te\\!xt'", shellescape("te!xt", 1))
call assert_equal("'te\nxt'", shellescape("te\nxt"))
call assert_equal("'te\\\nxt'", shellescape("te\nxt", 1))
set shell=tcsh
call assert_equal("'te\\!xt'", shellescape("te!xt"))
call assert_equal("'te\\\\!xt'", shellescape("te!xt", 1))
call assert_equal("'te\\\nxt'", shellescape("te\nxt"))
call assert_equal("'te\\\\\nxt'", shellescape("te\nxt", 1))
let &shell = save_shell
endfunc