diff options
-rw-r--r-- | src/nvim/search.h | 2 | ||||
-rw-r--r-- | src/nvim/strings.c | 6 | ||||
-rw-r--r-- | test/old/testdir/test_shell.vim | 4 |
3 files changed, 8 insertions, 4 deletions
diff --git a/src/nvim/search.h b/src/nvim/search.h index 783756b781..92ee5d6854 100644 --- a/src/nvim/search.h +++ b/src/nvim/search.h @@ -84,7 +84,7 @@ typedef struct { /// Structure containing last search pattern and its attributes. typedef struct { char *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). bool magic; ///< Magicness of the pattern. bool no_scs; ///< No smartcase for this pattern. Timestamp timestamp; ///< Time of the last change. diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 16ae35272b..8fef4ba7fd 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -268,9 +268,9 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli } if (do_special && find_cmdline_var(p, &l) >= 0) { *d++ = '\\'; // insert backslash - while (--l != SIZE_MAX) { // copy the var - *d++ = *p++; - } + memcpy(d, p, l); // copy the var + d += l; + p += l; continue; } if (*p == '\\' && fish_like) { diff --git a/test/old/testdir/test_shell.vim b/test/old/testdir/test_shell.vim index baaa327965..c2320d8f39 100644 --- a/test/old/testdir/test_shell.vim +++ b/test/old/testdir/test_shell.vim @@ -119,6 +119,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)) |