Karsten Hopp 1ce4c4
To: vim-dev@vim.org
Karsten Hopp 1ce4c4
Subject: Patch 7.3.025
Karsten Hopp 1ce4c4
Fcc: outbox
Karsten Hopp 1ce4c4
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 1ce4c4
Mime-Version: 1.0
Karsten Hopp 1ce4c4
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 1ce4c4
Content-Transfer-Encoding: 8bit
Karsten Hopp 1ce4c4
------------
Karsten Hopp 1ce4c4
Karsten Hopp 1ce4c4
Patch 7.3.025
Karsten Hopp 1ce4c4
Problem:    ":mksession" does not square brackets escape file name properly.
Karsten Hopp 1ce4c4
Solution:   Improve escapging of file names. (partly by Peter Odding)
Karsten Hopp 1ce4c4
Files:	    src/ex_docmd.c
Karsten Hopp 1ce4c4
Karsten Hopp 1ce4c4
Karsten Hopp 1ce4c4
*** ../vim-7.3.024/src/ex_docmd.c	2010-09-21 16:56:29.000000000 +0200
Karsten Hopp 1ce4c4
--- src/ex_docmd.c	2010-10-13 17:39:17.000000000 +0200
Karsten Hopp 1ce4c4
***************
Karsten Hopp 1ce4c4
*** 10708,10714 ****
Karsten Hopp 1ce4c4
   * Write a file name to the session file.
Karsten Hopp 1ce4c4
   * Takes care of the "slash" option in 'sessionoptions' and escapes special
Karsten Hopp 1ce4c4
   * characters.
Karsten Hopp 1ce4c4
!  * Returns FAIL if writing fails.
Karsten Hopp 1ce4c4
   */
Karsten Hopp 1ce4c4
      static int
Karsten Hopp 1ce4c4
  ses_put_fname(fd, name, flagp)
Karsten Hopp 1ce4c4
--- 10708,10714 ----
Karsten Hopp 1ce4c4
   * Write a file name to the session file.
Karsten Hopp 1ce4c4
   * Takes care of the "slash" option in 'sessionoptions' and escapes special
Karsten Hopp 1ce4c4
   * characters.
Karsten Hopp 1ce4c4
!  * Returns FAIL if writing fails or out of memory.
Karsten Hopp 1ce4c4
   */
Karsten Hopp 1ce4c4
      static int
Karsten Hopp 1ce4c4
  ses_put_fname(fd, name, flagp)
Karsten Hopp 1ce4c4
***************
Karsten Hopp 1ce4c4
*** 10717,10765 ****
Karsten Hopp 1ce4c4
      unsigned	*flagp;
Karsten Hopp 1ce4c4
  {
Karsten Hopp 1ce4c4
      char_u	*sname;
Karsten Hopp 1ce4c4
      int		retval = OK;
Karsten Hopp 1ce4c4
-     int		c;
Karsten Hopp 1ce4c4
  
Karsten Hopp 1ce4c4
      sname = home_replace_save(NULL, name);
Karsten Hopp 1ce4c4
!     if (sname != NULL)
Karsten Hopp 1ce4c4
! 	name = sname;
Karsten Hopp 1ce4c4
!     while (*name != NUL)
Karsten Hopp 1ce4c4
!     {
Karsten Hopp 1ce4c4
! #ifdef FEAT_MBYTE
Karsten Hopp 1ce4c4
! 	{
Karsten Hopp 1ce4c4
! 	    int l;
Karsten Hopp 1ce4c4
  
Karsten Hopp 1ce4c4
! 	    if (has_mbyte && (l = (*mb_ptr2len)(name)) > 1)
Karsten Hopp 1ce4c4
! 	    {
Karsten Hopp 1ce4c4
! 		/* copy a multibyte char */
Karsten Hopp 1ce4c4
! 		while (--l >= 0)
Karsten Hopp 1ce4c4
! 		{
Karsten Hopp 1ce4c4
! 		    if (putc(*name, fd) != *name)
Karsten Hopp 1ce4c4
! 			retval = FAIL;
Karsten Hopp 1ce4c4
! 		    ++name;
Karsten Hopp 1ce4c4
! 		}
Karsten Hopp 1ce4c4
! 		continue;
Karsten Hopp 1ce4c4
! 	    }
Karsten Hopp 1ce4c4
! 	}
Karsten Hopp 1ce4c4
! #endif
Karsten Hopp 1ce4c4
! 	c = *name++;
Karsten Hopp 1ce4c4
! 	if (c == '\\' && (*flagp & SSOP_SLASH))
Karsten Hopp 1ce4c4
! 	    /* change a backslash to a forward slash */
Karsten Hopp 1ce4c4
! 	    c = '/';
Karsten Hopp 1ce4c4
! 	else if ((vim_strchr(escape_chars, c) != NULL
Karsten Hopp 1ce4c4
! #ifdef BACKSLASH_IN_FILENAME
Karsten Hopp 1ce4c4
! 		    && c != '\\'
Karsten Hopp 1ce4c4
! #endif
Karsten Hopp 1ce4c4
! 		 ) || c == '#' || c == '%')
Karsten Hopp 1ce4c4
! 	{
Karsten Hopp 1ce4c4
! 	    /* escape a special character with a backslash */
Karsten Hopp 1ce4c4
! 	    if (putc('\\', fd) != '\\')
Karsten Hopp 1ce4c4
! 		retval = FAIL;
Karsten Hopp 1ce4c4
! 	}
Karsten Hopp 1ce4c4
! 	if (putc(c, fd) != c)
Karsten Hopp 1ce4c4
! 	    retval = FAIL;
Karsten Hopp 1ce4c4
      }
Karsten Hopp 1ce4c4
      vim_free(sname);
Karsten Hopp 1ce4c4
      return retval;
Karsten Hopp 1ce4c4
  }
Karsten Hopp 1ce4c4
  
Karsten Hopp 1ce4c4
--- 10717,10748 ----
Karsten Hopp 1ce4c4
      unsigned	*flagp;
Karsten Hopp 1ce4c4
  {
Karsten Hopp 1ce4c4
      char_u	*sname;
Karsten Hopp 1ce4c4
+     char_u	*p;
Karsten Hopp 1ce4c4
      int		retval = OK;
Karsten Hopp 1ce4c4
  
Karsten Hopp 1ce4c4
      sname = home_replace_save(NULL, name);
Karsten Hopp 1ce4c4
!     if (sname == NULL)
Karsten Hopp 1ce4c4
! 	return FAIL;
Karsten Hopp 1ce4c4
  
Karsten Hopp 1ce4c4
!     if (*flagp & SSOP_SLASH)
Karsten Hopp 1ce4c4
!     {
Karsten Hopp 1ce4c4
! 	/* change all backslashes to forward slashes */
Karsten Hopp 1ce4c4
! 	for (p = sname; *p != NUL; mb_ptr_adv(p))
Karsten Hopp 1ce4c4
! 	    if (*p == '\\')
Karsten Hopp 1ce4c4
! 		*p = '/';
Karsten Hopp 1ce4c4
      }
Karsten Hopp 1ce4c4
+ 
Karsten Hopp 1ce4c4
+     /* escapse special characters */
Karsten Hopp 1ce4c4
+     p = vim_strsave_fnameescape(sname, FALSE);
Karsten Hopp 1ce4c4
      vim_free(sname);
Karsten Hopp 1ce4c4
+     if (p == NULL)
Karsten Hopp 1ce4c4
+ 	return FAIL;
Karsten Hopp 1ce4c4
+ 
Karsten Hopp 1ce4c4
+     /* write the result */
Karsten Hopp 1ce4c4
+     if (fputs((char *)p, fd) < 0)
Karsten Hopp 1ce4c4
+ 	retval = FAIL;
Karsten Hopp 1ce4c4
+ 
Karsten Hopp 1ce4c4
+     vim_free(p);
Karsten Hopp 1ce4c4
      return retval;
Karsten Hopp 1ce4c4
  }
Karsten Hopp 1ce4c4
  
Karsten Hopp 1ce4c4
*** ../vim-7.3.024/src/version.c	2010-10-13 16:44:17.000000000 +0200
Karsten Hopp 1ce4c4
--- src/version.c	2010-10-13 17:49:15.000000000 +0200
Karsten Hopp 1ce4c4
***************
Karsten Hopp 1ce4c4
*** 716,717 ****
Karsten Hopp 1ce4c4
--- 716,719 ----
Karsten Hopp 1ce4c4
  {   /* Add new patch number below this line */
Karsten Hopp 1ce4c4
+ /**/
Karsten Hopp 1ce4c4
+     25,
Karsten Hopp 1ce4c4
  /**/
Karsten Hopp 1ce4c4
Karsten Hopp 1ce4c4
-- 
Karsten Hopp 1ce4c4
"Time flies like an arrow".  So I put an arrow on my desk, now
Karsten Hopp 1ce4c4
awaiting one of these time flies showing up.
Karsten Hopp 1ce4c4
Karsten Hopp 1ce4c4
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 1ce4c4
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 1ce4c4
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 1ce4c4
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///