Skip to content

Commit 2061552

Browse files
committed
patch 8.0.0625: shellescape() always escapes a newline
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 #1590)
1 parent 6c95fbc commit 2061552

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

src/evalfunc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10461,8 +10461,10 @@ f_sha256(typval_T *argvars, typval_T *rettv)
1046110461
static void
1046210462
f_shellescape(typval_T *argvars, typval_T *rettv)
1046310463
{
10464+
int do_special = non_zero_arg(&argvars[1]);
10465+
1046410466
rettv->vval.v_string = vim_strsave_shellescape(
10465-
get_tv_string(&argvars[0]), non_zero_arg(&argvars[1]), TRUE);
10467+
get_tv_string(&argvars[0]), do_special, do_special);
1046610468
rettv->v_type = VAR_STRING;
1046710469
}
1046810470

src/testdir/test_functions.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,3 +784,28 @@ func Test_redo_in_nested_functions()
784784
delfunc Operator
785785
delfunc Apply
786786
endfunc
787+
788+
func Test_shellescape()
789+
let save_shell = &shell
790+
set shell=bash
791+
call assert_equal("'text'", shellescape('text'))
792+
call assert_equal("'te\"xt'", shellescape('te"xt'))
793+
call assert_equal("'te'\\''xt'", shellescape("te'xt"))
794+
795+
call assert_equal("'te%xt'", shellescape("te%xt"))
796+
call assert_equal("'te\\%xt'", shellescape("te%xt", 1))
797+
call assert_equal("'te#xt'", shellescape("te#xt"))
798+
call assert_equal("'te\\#xt'", shellescape("te#xt", 1))
799+
call assert_equal("'te!xt'", shellescape("te!xt"))
800+
call assert_equal("'te\\!xt'", shellescape("te!xt", 1))
801+
802+
call assert_equal("'te\nxt'", shellescape("te\nxt"))
803+
call assert_equal("'te\\\nxt'", shellescape("te\nxt", 1))
804+
set shell=tcsh
805+
call assert_equal("'te\\!xt'", shellescape("te!xt"))
806+
call assert_equal("'te\\\\!xt'", shellescape("te!xt", 1))
807+
call assert_equal("'te\\\nxt'", shellescape("te\nxt"))
808+
call assert_equal("'te\\\\\nxt'", shellescape("te\nxt", 1))
809+
810+
let &shell = save_shell
811+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
625,
767769
/**/
768770
624,
769771
/**/

0 commit comments

Comments
 (0)