Skip to content

Commit a95ab32

Browse files
committed
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)
1 parent 38a3d6c commit a95ab32

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/diff.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ ex_diffpatch(exarg_T *eap)
906906
int browse_flag = cmdmod.browse;
907907
#endif
908908
stat_T st;
909+
char_u *esc_name = NULL;
909910

910911
#ifdef FEAT_BROWSE
911912
if (cmdmod.browse)
@@ -935,11 +936,14 @@ ex_diffpatch(exarg_T *eap)
935936
/* Get the absolute path of the patchfile, changing directory below. */
936937
fullname = FullName_save(eap->arg, FALSE);
937938
#endif
938-
buflen = STRLEN(tmp_orig) + (
939+
esc_name = vim_strsave_shellescape(
939940
# ifdef UNIX
940-
fullname != NULL ? STRLEN(fullname) :
941+
fullname != NULL ? fullname :
941942
# endif
942-
STRLEN(eap->arg)) + STRLEN(tmp_new) + 16;
943+
eap->arg, TRUE, TRUE);
944+
if (esc_name == NULL)
945+
goto theend;
946+
buflen = STRLEN(tmp_orig) + STRLEN(esc_name) + STRLEN(tmp_new) + 16;
943947
buf = alloc((unsigned)buflen);
944948
if (buf == NULL)
945949
goto theend;
@@ -977,17 +981,8 @@ ex_diffpatch(exarg_T *eap)
977981
{
978982
/* Build the patch command and execute it. Ignore errors. Switch to
979983
* cooked mode to allow the user to respond to prompts. */
980-
vim_snprintf((char *)buf, buflen,
981-
#ifdef UNIX
982-
"patch -o %s %s < '%s'",
983-
#else
984-
"patch -o %s %s < \"%s\"",
985-
#endif
986-
tmp_new, tmp_orig,
987-
# ifdef UNIX
988-
fullname != NULL ? fullname :
989-
# endif
990-
eap->arg);
984+
vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s",
985+
tmp_new, tmp_orig, esc_name);
991986
#ifdef FEAT_AUTOCMD
992987
block_autocmds(); /* Avoid ShellCmdPost stuff */
993988
#endif
@@ -1078,6 +1073,7 @@ ex_diffpatch(exarg_T *eap)
10781073
#ifdef UNIX
10791074
vim_free(fullname);
10801075
#endif
1076+
vim_free(esc_name);
10811077
#ifdef FEAT_BROWSE
10821078
vim_free(browseFile);
10831079
cmdmod.browse = browse_flag;

src/testdir/test_diffmode.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ func Test_diffpatch()
319319
new
320320
call assert_fails('diffpatch Xpatch', 'E816:')
321321

322-
for name in ['Xpatch', 'Xpatch$HOME']
322+
for name in ['Xpatch', 'Xpatch$HOME', 'Xpa''tch']
323323
call setline(1, ['1', '2', '3'])
324324
if name != 'Xpatch'
325325
call rename('Xpatch', name)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
444,
767769
/**/
768770
443,
769771
/**/

0 commit comments

Comments
 (0)