]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0451: No test for escaping '<' with shellescape() v9.1.0451
authorzeertzjq <zeertzjq@outlook.com>
Thu, 30 May 2024 17:27:25 +0000 (19:27 +0200)
committerChristian Brabandt <cb@256bit.org>
Thu, 30 May 2024 17:27:25 +0000 (19:27 +0200)
Problem:  No test for escaping '<' with shellescape()
Solution: Add a test.  Use memcpy() in code to make it easier to
          understand.  Fix a typo (zeertzjq).

closes: #14876

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/strings.c
src/structs.h
src/testdir/test_shell.vim
src/version.c

index 9b66ee0e4adce268e9a4cb4cc53c55c1578fcb18..6b2ff0a011842f0a237f9b496aed044e9da6c344 100644 (file)
@@ -269,12 +269,12 @@ vim_strsave_shellescape(char_u *string, int do_special, int do_newline)
                *d++ = *p++;
                continue;
            }
-           if (do_special && find_cmdline_var(p, &l) >= 0 && l > 0)
+           if (do_special && find_cmdline_var(p, &l) >= 0)
            {
                *d++ = '\\';            // insert backslash
-               do                      // copy the var
-                   *d++ = *p++;
-               while (--l > 0);
+               memcpy(d, p, l);        // copy the var
+               d += l;
+               p += l;
                continue;
            }
            if (*p == '\\' && fish_like)
index b5341e3bad7a6e7b1f618ac61f610093d1be8d28..804581bf1b5f5a84a170ff2c130221c833f6cc68 100644 (file)
@@ -4795,7 +4795,7 @@ typedef struct soffset
 typedef struct spat
 {
     char_u         *pat;       // the pattern (in allocated memory) or NULL
-    size_t         patlen;     // the length of the patten (0 is pat is NULL)
+    size_t         patlen;     // the length of the pattern (0 if pat is NULL)
     int                    magic;      // magicness of the pattern
     int                    no_scs;     // no smartcase for this pattern
     soffset_T      off;
index 7d91dff358133ae48e059fbb3cd26d36790f28cb..2ac559676f07eeeaa95cf782b5756804fc82e06f 100644 (file)
@@ -158,6 +158,10 @@ func Test_shellescape()
   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<cword>xt'", shellescape("te<cword>xt"))
+  call assert_equal("'te\\<cword>xt'", shellescape("te<cword>xt", 1))
+  call assert_equal("'te<cword>%xt'", shellescape("te<cword>%xt"))
+  call assert_equal("'te\\<cword>\\%xt'", shellescape("te<cword>%xt", 1))
 
   call assert_equal("'te\nxt'", shellescape("te\nxt"))
   call assert_equal("'te\\\nxt'", shellescape("te\nxt", 1))
index bedc35bf2ba534b32014f5273c32eef74eb7d327..e90bd3074e4788a6c0c695883de4980b77c20340 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    451,
 /**/
     450,
 /**/