]> granicus.if.org Git - vim/commitdiff
patch 8.0.0625: shellescape() always escapes a newline v8.0.0625
authorBram Moolenaar <Bram@vim.org>
Mon, 5 Jun 2017 16:46:26 +0000 (18:46 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 5 Jun 2017 16:46:26 +0000 (18:46 +0200)
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)

src/evalfunc.c
src/testdir/test_functions.vim
src/version.c

index 60cd344243700961e66939127be0de8412a9e954..c198df13a920f5d4320acf1937bf2b359c3fe9a6 100644 (file)
@@ -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;
 }
 
index e569ef1dcaa642e1a230fcbc45b120708030cd5c..f0f656ac8593ca59f7ba421d729d0437131e19a1 100644 (file)
@@ -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
index c066c8175551d89899e9add40a17c384fe7a8b0c..0280ca810a05d5ccc4f4033b5b9fde075ffea422 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    625,
 /**/
     624,
 /**/