From 456cf72974865cecf489bc5a5b4003c22745a77d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 21 Jan 2018 10:28:52 +0100 Subject: vim-patch:8.0.0442: patch shell command not well escaped Problem: Patch shell command uses double quotes around the argument, which allows for $HOME to be expanded. (Etienne) Solution: Use single quotes on Unix. (closes vim/vim#1543) https://github.com/vim/vim/commit/1ef73e33c9414eb02c229d8234aafd9d481a8856 --- src/nvim/diff.c | 2 +- src/nvim/testdir/test_diffmode.vim | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/diff.c b/src/nvim/diff.c index dd489c18e9..4db81a97a2 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -925,7 +925,7 @@ void ex_diffpatch(exarg_T *eap) } else { // Build the patch command and execute it. Ignore errors. #ifdef UNIX - vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"", + vim_snprintf((char *)buf, buflen, "patch -o %s %s < '%s'", tmp_new, tmp_orig, fullname != NULL ? fullname : eap->arg); #else vim_snprintf((char *)buf, buflen, "patch -o %s %s < \"%s\"", diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index b5a76909a2..430d02c2c3 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -501,9 +501,20 @@ func Test_diffpatch() bwipe! new call assert_fails('diffpatch Xpatch', 'E816:') - call setline(1, ['1', '2', '3']) - diffpatch Xpatch - call assert_equal(['1', '2x', '3', '4'], getline(1, '$')) + + for name in ['Xpatch', 'Xpatch$HOME'] + call setline(1, ['1', '2', '3']) + if name != 'Xpatch' + call rename('Xpatch', name) + endif + exe 'diffpatch ' . escape(name, '$') + call assert_equal(['1', '2x', '3', '4'], getline(1, '$')) + if name != 'Xpatch' + call rename(name, 'Xpatch') + endif + bwipe! + endfor + call delete('Xpatch') bwipe! endfunc -- cgit