1
0
forked from aniani/vim

patch 8.0.0444: diffpatch fails when the file name has a quote

Problem:    Diffpatch fails when the file name has a quote.
Solution:   Escape the name properly. (zetzei)
This commit is contained in:
Bram Moolenaar
2017-03-11 19:21:53 +01:00
parent 38a3d6c960
commit a95ab32120
3 changed files with 13 additions and 15 deletions

View File

@@ -906,6 +906,7 @@ ex_diffpatch(exarg_T *eap)
int browse_flag = cmdmod.browse; int browse_flag = cmdmod.browse;
#endif #endif
stat_T st; stat_T st;
char_u *esc_name = NULL;
#ifdef FEAT_BROWSE #ifdef FEAT_BROWSE
if (cmdmod.browse) if (cmdmod.browse)
@@ -935,11 +936,14 @@ ex_diffpatch(exarg_T *eap)
/* Get the absolute path of the patchfile, changing directory below. */ /* Get the absolute path of the patchfile, changing directory below. */
fullname = FullName_save(eap->arg, FALSE); fullname = FullName_save(eap->arg, FALSE);
#endif #endif
buflen = STRLEN(tmp_orig) + ( esc_name = vim_strsave_shellescape(
# ifdef UNIX # ifdef UNIX
fullname != NULL ? STRLEN(fullname) : fullname != NULL ? fullname :
# endif # 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); buf = alloc((unsigned)buflen);
if (buf == NULL) if (buf == NULL)
goto theend; goto theend;
@@ -977,17 +981,8 @@ ex_diffpatch(exarg_T *eap)
{ {
/* Build the patch command and execute it. Ignore errors. Switch to /* Build the patch command and execute it. Ignore errors. Switch to
* cooked mode to allow the user to respond to prompts. */ * cooked mode to allow the user to respond to prompts. */
vim_snprintf((char *)buf, buflen, vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s",
#ifdef UNIX tmp_new, tmp_orig, esc_name);
"patch -o %s %s < '%s'",
#else
"patch -o %s %s < \"%s\"",
#endif
tmp_new, tmp_orig,
# ifdef UNIX
fullname != NULL ? fullname :
# endif
eap->arg);
#ifdef FEAT_AUTOCMD #ifdef FEAT_AUTOCMD
block_autocmds(); /* Avoid ShellCmdPost stuff */ block_autocmds(); /* Avoid ShellCmdPost stuff */
#endif #endif
@@ -1078,6 +1073,7 @@ theend:
#ifdef UNIX #ifdef UNIX
vim_free(fullname); vim_free(fullname);
#endif #endif
vim_free(esc_name);
#ifdef FEAT_BROWSE #ifdef FEAT_BROWSE
vim_free(browseFile); vim_free(browseFile);
cmdmod.browse = browse_flag; cmdmod.browse = browse_flag;

View File

@@ -319,7 +319,7 @@ func Test_diffpatch()
new new
call assert_fails('diffpatch Xpatch', 'E816:') 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']) call setline(1, ['1', '2', '3'])
if name != 'Xpatch' if name != 'Xpatch'
call rename('Xpatch', name) call rename('Xpatch', name)

View File

@@ -764,6 +764,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
444,
/**/ /**/
443, 443,
/**/ /**/