To: vim_dev@googlegroups.com Subject: Patch 8.1.2278 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2278 Problem: Using "cd" with "exe" may fail. Solution: Use chdir() instead. Files: src/testdir/test_autochdir.vim, src/testdir/test_autocmd.vim, src/testdir/test_cd.vim, src/testdir/test_expand.vim, src/testdir/test_find_complete.vim, src/testdir/test_findfile.vim, src/testdir/test_getcwd.vim, src/testdir/test_shortpathname.vim *** ../vim-8.1.2277/src/testdir/test_autochdir.vim 2019-08-07 23:07:03.956858953 +0200 --- src/testdir/test_autochdir.vim 2019-11-09 17:54:32.029926717 +0100 *************** *** 21,26 **** bwipe! au! DirChanged set noacd ! exe 'cd ' . cwd call delete('samples/Xtest') endfunc --- 21,26 ---- bwipe! au! DirChanged set noacd ! call chdir(cwd) call delete('samples/Xtest') endfunc *** ../vim-8.1.2277/src/testdir/test_autocmd.vim 2019-10-11 21:19:10.397931898 +0200 --- src/testdir/test_autocmd.vim 2019-11-09 17:57:10.033071547 +0100 *************** *** 1731,1737 **** endfunc function s:After_test_dirchanged() ! exe 'cd' s:dir_this call delete(s:dir_foo, 'd') call delete(s:dir_bar, 'd') augroup test_dirchanged --- 1731,1737 ---- endfunc function s:After_test_dirchanged() ! call chdir(s:dir_this) call delete(s:dir_foo, 'd') call delete(s:dir_bar, 'd') augroup test_dirchanged *************** *** 1743,1753 **** call s:Before_test_dirchanged() autocmd test_dirchanged DirChanged global call add(s:li, "cd:") autocmd test_dirchanged DirChanged global call add(s:li, expand("")) ! exe 'cd' s:dir_foo call assert_equal(["cd:", s:dir_foo], s:li) ! exe 'cd' s:dir_foo call assert_equal(["cd:", s:dir_foo], s:li) ! exe 'lcd' s:dir_bar call assert_equal(["cd:", s:dir_foo], s:li) call s:After_test_dirchanged() endfunc --- 1743,1753 ---- call s:Before_test_dirchanged() autocmd test_dirchanged DirChanged global call add(s:li, "cd:") autocmd test_dirchanged DirChanged global call add(s:li, expand("")) ! call chdir(s:dir_foo) call assert_equal(["cd:", s:dir_foo], s:li) ! call chdir(s:dir_foo) call assert_equal(["cd:", s:dir_foo], s:li) ! exe 'lcd ' .. fnameescape(s:dir_bar) call assert_equal(["cd:", s:dir_foo], s:li) call s:After_test_dirchanged() endfunc *************** *** 1756,1766 **** call s:Before_test_dirchanged() autocmd test_dirchanged DirChanged window call add(s:li, "lcd:") autocmd test_dirchanged DirChanged window call add(s:li, expand("")) ! exe 'cd' s:dir_foo call assert_equal([], s:li) ! exe 'lcd' s:dir_bar call assert_equal(["lcd:", s:dir_bar], s:li) ! exe 'lcd' s:dir_bar call assert_equal(["lcd:", s:dir_bar], s:li) call s:After_test_dirchanged() endfunc --- 1756,1766 ---- call s:Before_test_dirchanged() autocmd test_dirchanged DirChanged window call add(s:li, "lcd:") autocmd test_dirchanged DirChanged window call add(s:li, expand("")) ! call chdir(s:dir_foo) call assert_equal([], s:li) ! exe 'lcd ' .. fnameescape(s:dir_bar) call assert_equal(["lcd:", s:dir_bar], s:li) ! exe 'lcd ' .. fnameescape(s:dir_bar) call assert_equal(["lcd:", s:dir_bar], s:li) call s:After_test_dirchanged() endfunc *************** *** 1774,1780 **** autocmd test_dirchanged DirChanged auto call add(s:li, "auto:") autocmd test_dirchanged DirChanged auto call add(s:li, expand("")) set acd ! exe 'cd ..' call assert_equal([], s:li) exe 'edit ' . s:dir_foo . '/Xfile' call assert_equal(s:dir_foo, getcwd()) --- 1774,1780 ---- autocmd test_dirchanged DirChanged auto call add(s:li, "auto:") autocmd test_dirchanged DirChanged auto call add(s:li, expand("")) set acd ! cd .. call assert_equal([], s:li) exe 'edit ' . s:dir_foo . '/Xfile' call assert_equal(s:dir_foo, getcwd()) *** ../vim-8.1.2277/src/testdir/test_cd.vim 2019-08-24 22:58:08.307264136 +0200 --- src/testdir/test_cd.vim 2019-11-09 17:59:16.820481620 +0100 *************** *** 9,15 **** let path = getcwd() cd .. call assert_notequal(path, getcwd()) ! exe 'cd ' . path call assert_equal(path, getcwd()) endfunc --- 9,15 ---- let path = getcwd() cd .. call assert_notequal(path, getcwd()) ! exe 'cd ' .. fnameescape(path) call assert_equal(path, getcwd()) endfunc *************** *** 20,26 **** cd call assert_equal($HOME, getcwd()) call assert_notequal(path, getcwd()) ! exe 'cd ' . path call assert_equal(path, getcwd()) else " Test that cd without argument echoes cwd on non-Unix systems. --- 20,26 ---- cd call assert_equal($HOME, getcwd()) call assert_notequal(path, getcwd()) ! exe 'cd ' .. fnameescape(path) call assert_equal(path, getcwd()) else " Test that cd without argument echoes cwd on non-Unix systems. *************** *** 58,64 **** " :cd should succeed when buffer has been written. w! ! exe 'cd ' . path call assert_equal(path, getcwd()) call delete('Xfoo') --- 58,64 ---- " :cd should succeed when buffer has been written. w! ! exe 'cd ' .. fnameescape(path) call assert_equal(path, getcwd()) call delete('Xfoo') *************** *** 103,108 **** call assert_equal("", d) only | tabonly ! exe 'cd ' . topdir call delete('Xdir', 'rf') endfunc --- 103,108 ---- call assert_equal("", d) only | tabonly ! call chdir(topdir) call delete('Xdir', 'rf') endfunc *** ../vim-8.1.2277/src/testdir/test_expand.vim 2019-08-24 20:49:58.825320302 +0200 --- src/testdir/test_expand.vim 2019-11-09 17:59:44.456336148 +0100 *************** *** 35,41 **** call assert_true(isdirectory('Xdir ~ dir')) cd Xdir\ ~\ dir call assert_true(getcwd() =~ 'Xdir \~ dir') ! exe 'cd ' . fnameescape(dir) call delete('Xdir ~ dir', 'd') call assert_false(isdirectory('Xdir ~ dir')) endfunc --- 35,41 ---- call assert_true(isdirectory('Xdir ~ dir')) cd Xdir\ ~\ dir call assert_true(getcwd() =~ 'Xdir \~ dir') ! call chdir(dir) call delete('Xdir ~ dir', 'd') call assert_false(isdirectory('Xdir ~ dir')) endfunc *** ../vim-8.1.2277/src/testdir/test_find_complete.vim 2018-02-03 20:29:55.000000000 +0100 --- src/testdir/test_find_complete.vim 2019-11-09 18:01:28.259751093 +0100 *************** *** 36,42 **** " We shouldn't find any file till this point call mkdir('in/path', 'p') ! exe 'cd ' . cwd call writefile(['Holy Grail'], 'Xfind/file.txt') call writefile(['Jimmy Hoffa'], 'Xfind/in/file.txt') call writefile(['Another Holy Grail'], 'Xfind/in/stuff.txt') --- 36,42 ---- " We shouldn't find any file till this point call mkdir('in/path', 'p') ! call chdir(cwd) call writefile(['Holy Grail'], 'Xfind/file.txt') call writefile(['Jimmy Hoffa'], 'Xfind/in/file.txt') call writefile(['Another Holy Grail'], 'Xfind/in/stuff.txt') *************** *** 133,144 **** call assert_equal('Voyager 2', getline(1)) " Check for correct handling of shorten_fname()'s behavior on windows ! exec "cd " . cwd . "/Xfind/in" call feedkeys(":find file\t\n", "xt") call assert_equal('Jimmy Hoffa', getline(1)) " Test for relative to current buffer 'path' item ! exec "cd " . cwd . "/Xfind/" set path=./path " Open the file where Jimmy Hoffa is found e in/file.txt --- 133,144 ---- call assert_equal('Voyager 2', getline(1)) " Check for correct handling of shorten_fname()'s behavior on windows ! call chdir(cwd .. "/Xfind/in") call feedkeys(":find file\t\n", "xt") call assert_equal('Jimmy Hoffa', getline(1)) " Test for relative to current buffer 'path' item ! call chdir(cwd . "/Xfind/") set path=./path " Open the file where Jimmy Hoffa is found e in/file.txt *************** *** 157,163 **** call assert_equal('Another Holy Grail', getline(1)) enew | only ! exe 'cd ' . cwd call delete('Xfind', 'rf') set path& endfunc --- 157,163 ---- call assert_equal('Another Holy Grail', getline(1)) enew | only ! call chdir(cwd) call delete('Xfind', 'rf') set path& endfunc *** ../vim-8.1.2277/src/testdir/test_findfile.vim 2019-08-24 20:49:58.825320302 +0200 --- src/testdir/test_findfile.vim 2019-11-09 18:01:54.875593109 +0100 *************** *** 113,119 **** call assert_match('.*/Xdir1/bar', findfile('bar', '**;', 2)) bwipe! ! exe 'cd ' . save_dir call CleanFiles() let &path = save_path let &shellslash = save_shellslash --- 113,119 ---- call assert_match('.*/Xdir1/bar', findfile('bar', '**;', 2)) bwipe! ! call chdir(save_dir) call CleanFiles() let &path = save_path let &shellslash = save_shellslash *************** *** 170,176 **** call assert_match('.*/Xdir1/Xdir2', finddir('Xdir2', '**;', 2)) call assert_equal('Xdir3', finddir('Xdir3', '**;', 1)) ! exe 'cd ' . save_dir call CleanFiles() let &path = save_path let &shellslash = save_shellslash --- 170,176 ---- call assert_match('.*/Xdir1/Xdir2', finddir('Xdir2', '**;', 2)) call assert_equal('Xdir3', finddir('Xdir3', '**;', 1)) ! call chdir(save_dir) call CleanFiles() let &path = save_path let &shellslash = save_shellslash *** ../vim-8.1.2277/src/testdir/test_getcwd.vim 2019-09-01 20:16:48.003438501 +0200 --- src/testdir/test_getcwd.vim 2019-11-09 18:02:07.771515630 +0100 *************** *** 46,52 **** let g:cwd=getcwd() function TearDown() q ! exec "cd " . g:cwd call delete("Xtopdir", "rf") endfunction --- 46,52 ---- let g:cwd=getcwd() function TearDown() q ! call chdir(g:cwd) call delete("Xtopdir", "rf") endfunction *** ../vim-8.1.2277/src/testdir/test_shortpathname.vim 2019-10-30 04:10:00.053774871 +0100 --- src/testdir/test_shortpathname.vim 2019-11-09 18:02:39.571322080 +0100 *************** *** 51,57 **** call TestIt(file2, ':p:8', resfile2) call TestIt(nofile2, ':p:8', resnofile2) call TestIt(nofile2, ':p:8:h', fnamemodify(resnofile2, ':h')) ! exe 'cd ' . dir1 call TestIt(file1, ':.:8', strpart(resfile1, strlen(resdir1)+1)) call TestIt(nofile1, ':.:8', strpart(resnofile1, strlen(resdir1)+1)) call TestIt(file2, ':.:8', strpart(resfile2, strlen(resdir1)+1)) --- 51,57 ---- call TestIt(file2, ':p:8', resfile2) call TestIt(nofile2, ':p:8', resnofile2) call TestIt(nofile2, ':p:8:h', fnamemodify(resnofile2, ':h')) ! call chdir(dir1) call TestIt(file1, ':.:8', strpart(resfile1, strlen(resdir1)+1)) call TestIt(nofile1, ':.:8', strpart(resnofile1, strlen(resdir1)+1)) call TestIt(file2, ':.:8', strpart(resfile2, strlen(resdir1)+1)) *************** *** 68,74 **** call delete(dir2, 'd') call delete(dir1, 'd') ! exe "cd " . save_dir endfunc func Test_ColonEight_MultiByte() --- 68,74 ---- call delete(dir2, 'd') call delete(dir1, 'd') ! call chdir(save_dir) endfunc func Test_ColonEight_MultiByte() *** ../vim-8.1.2277/src/version.c 2019-11-09 20:00:32.325221562 +0100 --- src/version.c 2019-11-09 20:08:34.773884740 +0100 *************** *** 743,744 **** --- 743,746 ---- { /* Add new patch number below this line */ + /**/ + 2278, /**/ -- Never go to the toilet in a paperless office. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///