summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-03-11 19:21:53 +0100
committerBram Moolenaar <Bram@vim.org>2017-03-11 19:21:53 +0100
commita95ab321200f0239991bf53756b17cd7b90745f9 (patch)
tree6485aa8f07294fdda7cc42dff6fb948cbff23a0e
parent38a3d6c9601b637a28f399059263300e9f65eba4 (diff)
downloadvim-git-a95ab321200f0239991bf53756b17cd7b90745f9.tar.gz
patch 8.0.0444: diffpatch fails when the file name has a quotev8.0.0444
Problem: Diffpatch fails when the file name has a quote. Solution: Escape the name properly. (zetzei)
-rw-r--r--src/diff.c24
-rw-r--r--src/testdir/test_diffmode.vim2
-rw-r--r--src/version.c2
3 files changed, 13 insertions, 15 deletions
diff --git a/src/diff.c b/src/diff.c
index 7b81feba7..435269984 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -906,6 +906,7 @@ ex_diffpatch(exarg_T *eap)
int browse_flag = cmdmod.browse;
#endif
stat_T st;
+ char_u *esc_name = NULL;
#ifdef FEAT_BROWSE
if (cmdmod.browse)
@@ -935,11 +936,14 @@ ex_diffpatch(exarg_T *eap)
/* Get the absolute path of the patchfile, changing directory below. */
fullname = FullName_save(eap->arg, FALSE);
#endif
- buflen = STRLEN(tmp_orig) + (
+ esc_name = vim_strsave_shellescape(
# ifdef UNIX
- fullname != NULL ? STRLEN(fullname) :
+ fullname != NULL ? fullname :
# endif
- STRLEN(eap->arg)) + STRLEN(tmp_new) + 16;
+ eap->arg, TRUE, TRUE);
+ if (esc_name == NULL)
+ goto theend;
+ buflen = STRLEN(tmp_orig) + STRLEN(esc_name) + STRLEN(tmp_new) + 16;
buf = alloc((unsigned)buflen);
if (buf == NULL)
goto theend;
@@ -977,17 +981,8 @@ ex_diffpatch(exarg_T *eap)
{
/* Build the patch command and execute it. Ignore errors. Switch to
* cooked mode to allow the user to respond to prompts. */
- vim_snprintf((char *)buf, buflen,
-#ifdef UNIX
- "patch -o %s %s < '%s'",
-#else
- "patch -o %s %s < \"%s\"",
-#endif
- tmp_new, tmp_orig,
-# ifdef UNIX
- fullname != NULL ? fullname :
-# endif
- eap->arg);
+ vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s",
+ tmp_new, tmp_orig, esc_name);
#ifdef FEAT_AUTOCMD
block_autocmds(); /* Avoid ShellCmdPost stuff */
#endif
@@ -1078,6 +1073,7 @@ theend:
#ifdef UNIX
vim_free(fullname);
#endif
+ vim_free(esc_name);
#ifdef FEAT_BROWSE
vim_free(browseFile);
cmdmod.browse = browse_flag;
diff --git a/src/testdir/test_diffmode.vim b/src/testdir/test_diffmode.vim
index c23e8a1da..e09bcaa44 100644
--- a/src/testdir/test_diffmode.vim
+++ b/src/testdir/test_diffmode.vim
@@ -319,7 +319,7 @@ func Test_diffpatch()
new
call assert_fails('diffpatch Xpatch', 'E816:')
- for name in ['Xpatch', 'Xpatch$HOME']
+ for name in ['Xpatch', 'Xpatch$HOME', 'Xpa''tch']
call setline(1, ['1', '2', '3'])
if name != 'Xpatch'
call rename('Xpatch', name)
diff --git a/src/version.c b/src/version.c
index 5a58f4317..db00cc7d2 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 */
/**/
+ 444,
+/**/
443,
/**/
442,