To: vim_dev@googlegroups.com Subject: Patch 8.2.1793 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1793 Problem: Not consistently giving the "is a directory" warning. Solution: Adjust check for illegal file name and directory. (Yasuhiro Matsumoto, closes #7067) Files: src/fileio.c, src/testdir/test_edit.vim *** ../vim-8.2.1792/src/fileio.c 2020-09-02 21:21:30.964799806 +0200 --- src/fileio.c 2020-10-03 17:04:09.010339682 +0200 *************** *** 211,216 **** --- 211,217 ---- char_u *old_b_fname; int using_b_ffname; int using_b_fname; + static char *msg_is_a_directory = N_("is a directory"); au_did_filetype = FALSE; // reset before triggering any autocommands *************** *** 310,331 **** else msg_scroll = TRUE; // don't overwrite previous file message - /* - * If the name ends in a path separator, we can't open it. Check here, - * because reading the file may actually work, but then creating the swap - * file may destroy it! Reported on MS-DOS and Win 95. - * If the name is too long we might crash further on, quit here. - */ if (fname != NULL && *fname != NUL) { ! p = fname + STRLEN(fname); ! if (after_pathsep(fname, p) || STRLEN(fname) >= MAXPATHL) { filemess(curbuf, fname, (char_u *)_("Illegal file name"), 0); msg_end(); msg_scroll = msg_save; return FAIL; } } if (!read_stdin && !read_buffer && !read_fifo) --- 311,339 ---- else msg_scroll = TRUE; // don't overwrite previous file message if (fname != NULL && *fname != NUL) { ! size_t namelen = STRLEN(fname); ! ! // If the name is too long we might crash further on, quit here. ! if (namelen >= MAXPATHL) { filemess(curbuf, fname, (char_u *)_("Illegal file name"), 0); msg_end(); msg_scroll = msg_save; return FAIL; } + + // If the name ends in a path separator, we can't open it. Check here, + // because reading the file may actually work, but then creating the + // swap file may destroy it! Reported on MS-DOS and Win 95. + if (after_pathsep(fname, fname + namelen)) + { + filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); + msg_end(); + msg_scroll = msg_save; + return FAIL; + } } if (!read_stdin && !read_buffer && !read_fifo) *************** *** 349,355 **** if (S_ISDIR(perm)) { ! filemess(curbuf, fname, (char_u *)_("is a directory"), 0); retval = NOTDONE; } else --- 357,363 ---- if (S_ISDIR(perm)) { ! filemess(curbuf, fname, (char_u *)_(msg_is_a_directory), 0); retval = NOTDONE; } else *************** *** 475,481 **** perm = mch_getperm(fname); // check if the file exists if (isdir_f) { ! filemess(curbuf, sfname, (char_u *)_("is a directory"), 0); curbuf->b_p_ro = TRUE; // must use "w!" now } else --- 483,489 ---- perm = mch_getperm(fname); // check if the file exists if (isdir_f) { ! filemess(curbuf, sfname, (char_u *)_(msg_is_a_directory), 0); curbuf->b_p_ro = TRUE; // must use "w!" now } else *** ../vim-8.2.1792/src/testdir/test_edit.vim 2020-08-12 18:50:31.875655822 +0200 --- src/testdir/test_edit.vim 2020-10-03 16:47:22.560969278 +0200 *************** *** 1587,1592 **** --- 1587,1617 ---- close! endfunc + " Test for editing a directory + func Test_edit_is_a_directory() + CheckEnglish + let dirname = getcwd() . "/Xdir" + call mkdir(dirname, 'p') + + new + redir => msg + exe 'edit' dirname + redir END + call assert_match("is a directory$", split(msg, "\n")[0]) + bwipe! + + let dirname .= '/' + + new + redir => msg + exe 'edit' dirname + redir END + call assert_match("is a directory$", split(msg, "\n")[0]) + bwipe! + + call delete(dirname, 'rf') + endfunc + " Test for editing a file using invalid file encoding func Test_edit_invalid_encoding() CheckEnglish *** ../vim-8.2.1792/src/version.c 2020-10-03 14:23:46.156413453 +0200 --- src/version.c 2020-10-03 16:44:31.213386496 +0200 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 1793, /**/ -- I am also told that there is a logical proof out there somewhere that demonstrates that there is no task which duct tape cannot handle. -- Paul Brannan /// 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 ///