summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-06-05 18:46:26 +0200
committerBram Moolenaar <Bram@vim.org>2017-06-05 18:46:26 +0200
commit206155280def51160a9d81d983aed639015ffb44 (patch)
tree1143d17e10d8b407fdabe0ced2a63b4fee28373b /src
parent6c95fbc9ae64f3a7619070e830f0c35aa4f0ada9 (diff)
patch 8.0.0625: shellescape() always escapes a newlinev8.0.0625
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)
Diffstat (limited to 'src')
-rw-r--r--src/evalfunc.c4
-rw-r--r--src/testdir/test_functions.vim25
-rw-r--r--src/version.c2
3 files changed, 30 insertions, 1 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 60cd344243..c198df13a9 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -10461,8 +10461,10 @@ f_sha256(typval_T *argvars, typval_T *rettv)
static void
f_shellescape(typval_T *argvars, typval_T *rettv)
{
+ int do_special = non_zero_arg(&argvars[1]);
+
rettv->vval.v_string = vim_strsave_shellescape(
- get_tv_string(&argvars[0]), non_zero_arg(&argvars[1]), TRUE);
+ get_tv_string(&argvars[0]), do_special, do_special);
rettv->v_type = VAR_STRING;
}
diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim
index e569ef1dca..f0f656ac85 100644
--- a/src/testdir/test_functions.vim
+++ b/src/testdir/test_functions.vim
@@ -784,3 +784,28 @@ func Test_redo_in_nested_functions()
delfunc Operator
delfunc Apply
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
diff --git a/src/version.c b/src/version.c
index c066c81755..0280ca810a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -765,6 +765,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 625,
+/**/
624,
/**/
623,