To: vim-dev@vim.org Subject: Patch 6.3a.011 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.3a.011 Problem: Using the explorer plugin changes a local directory to the global directory. Solution: Don't use ":chdir" to restore the current directory. Make "expand('%:p')" remove "/../" and "/./" items from the path. Files: runtime/plugin/explorer.vim, src/eval.c, src/os_unix.c *** ../vim-6.3a.010/runtime/plugin/explorer.vim Fri May 7 10:59:32 2004 --- runtime/plugin/explorer.vim Wed May 12 11:30:24 2004 *************** *** 1,7 **** "============================================================================= " File: explorer.vim " Author: M A Aziz Ahmed (aziz@acorn-networks.com - doesn't work) ! " Last Change: 2004 Mar 15 " Version: 2.5 + changes " Additions by Mark Waggoner (waggoner@aracnet.com) et al. "----------------------------------------------------------------------------- --- 1,7 ---- "============================================================================= " File: explorer.vim " Author: M A Aziz Ahmed (aziz@acorn-networks.com - doesn't work) ! " Last Change: 2004 May 12 " Version: 2.5 + changes " Additions by Mark Waggoner (waggoner@aracnet.com) et al. "----------------------------------------------------------------------------- *************** *** 283,299 **** endif " Get the complete path to the directory to look at with a slash at ! " the end let b:completePath = s:Path(expand("%:p")) - " Save the directory we are currently in and chdir to the directory - " we are editing so that we can get a real path to the directory, - " eliminating things like ".." - let origdir= s:Path(getcwd()) - exe "chdir" escape(b:completePath, s:escfilename) - let b:completePath = s:Path(getcwd()) - exe "chdir" escape(origdir, s:escfilename) - " Add a slash at the end if b:completePath !~ '/$' let b:completePath = b:completePath . '/' --- 283,291 ---- endif " Get the complete path to the directory to look at with a slash at ! " the end. This also removes "/../" and "/./" things. let b:completePath = s:Path(expand("%:p")) " Add a slash at the end if b:completePath !~ '/$' let b:completePath = b:completePath . '/' *************** *** 518,529 **** endif " Is it a directory? If so, get a real path to it instead of ! " relative path if isdirectory(fn) ! let origdir= s:Path(getcwd()) ! exe "chdir" escape(fn,s:escfilename) ! let fn = s:Path(getcwd()) ! exe "chdir" escape(origdir,s:escfilename) endif " Open the new window --- 510,518 ---- endif " Is it a directory? If so, get a real path to it instead of ! " relative path. This also removes "/../" and "/./" things. if isdirectory(fn) ! let fn = fnamemodify(fn, ":p") endif " Open the new window *************** *** 585,596 **** let s:longlist = w:longlist " Get the file name ! let fn=s:GetFullFileName() if isdirectory(fn) ! let origdir= s:Path(getcwd()) ! exe "chdir" escape(fn,s:escfilename) ! let fn = s:Path(getcwd()) ! exe "chdir" escape(origdir,s:escfilename) endif " Move to desired window if needed --- 574,583 ---- let s:longlist = w:longlist " Get the file name ! let fn = s:GetFullFileName() if isdirectory(fn) ! " This removes "/../" and "/./" things. ! let fn = fnamemodify(fn, ":p") endif " Move to desired window if needed *** ../vim-6.3a.010/src/eval.c Fri May 7 10:59:40 2004 --- src/eval.c Tue May 11 18:05:00 2004 *************** *** 10276,10290 **** if (*fnamep == NULL) return -1; } /* FullName_save() is slow, don't use it when not needed. */ ! else if (!vim_isAbsName(*fnamep)) { ! *fnamep = FullName_save(*fnamep, FALSE); vim_free(*bufp); /* free any allocated file name */ *bufp = *fnamep; if (*fnamep == NULL) return -1; } /* Append a path separator to a directory. */ if (mch_isdir(*fnamep)) { --- 10276,10304 ---- if (*fnamep == NULL) return -1; } + + /* When "/." or "/.." is used: force expansion to get rid of it. */ + for (p = *fnamep; *p != NUL; ++p) + { + if (vim_ispathsep(*p) + && p[1] == '.' + && (p[2] == NUL + || vim_ispathsep(p[2]) + || (p[2] == '.' + && (p[3] == NUL || vim_ispathsep(p[3]))))) + break; + } + /* FullName_save() is slow, don't use it when not needed. */ ! if (*p != NUL || !vim_isAbsName(*fnamep)) { ! *fnamep = FullName_save(*fnamep, *p != NUL); vim_free(*bufp); /* free any allocated file name */ *bufp = *fnamep; if (*fnamep == NULL) return -1; } + /* Append a path separator to a directory. */ if (mch_isdir(*fnamep)) { *** ../vim-6.3a.010/src/os_unix.c Fri May 7 10:59:38 2004 --- src/os_unix.c Tue May 11 20:02:42 2004 *************** *** 2227,2233 **** #ifndef VMS else { ! if (l > 0 && buf[l - 1] != '/' && *fname != NUL) STRCAT(buf, "/"); } #endif --- 2227,2234 ---- #ifndef VMS else { ! if (l > 0 && buf[l - 1] != '/' && *fname != NUL ! && STRCMP(fname, ".") != 0) STRCAT(buf, "/"); } #endif *************** *** 2236,2242 **** if (retval == FAIL || STRLEN(buf) + STRLEN(fname) >= len) return FAIL; ! STRCAT(buf, fname); return OK; } --- 2237,2245 ---- if (retval == FAIL || STRLEN(buf) + STRLEN(fname) >= len) return FAIL; ! /* Do not append ".", "/dir/." is equal to "/dir". */ ! if (STRCMP(fname, ".") != 0) ! STRCAT(buf, fname); return OK; } *** ../vim-6.3a.010/src/version.c Tue May 11 22:32:13 2004 --- src/version.c Wed May 12 14:10:47 2004 *************** *** 643,644 **** --- 643,646 ---- { /* Add new patch number below this line */ + /**/ + 11, /**/ -- hundred-and-one symptoms of being an internet addict: 262. Your computer has it's own phone line - but your daughter doesn't. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///