To: vim-dev@vim.org
Subject: Patch 7.3.025
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.025
Problem:    ":mksession" does not square brackets escape file name properly.
Solution:   Improve escapging of file names. (partly by Peter Odding)
Files:	    src/ex_docmd.c


*** ../vim-7.3.024/src/ex_docmd.c	2010-09-21 16:56:29.000000000 +0200
--- src/ex_docmd.c	2010-10-13 17:39:17.000000000 +0200
***************
*** 10708,10714 ****
   * Write a file name to the session file.
   * Takes care of the "slash" option in 'sessionoptions' and escapes special
   * characters.
!  * Returns FAIL if writing fails.
   */
      static int
  ses_put_fname(fd, name, flagp)
--- 10708,10714 ----
   * Write a file name to the session file.
   * Takes care of the "slash" option in 'sessionoptions' and escapes special
   * characters.
!  * Returns FAIL if writing fails or out of memory.
   */
      static int
  ses_put_fname(fd, name, flagp)
***************
*** 10717,10765 ****
      unsigned	*flagp;
  {
      char_u	*sname;
      int		retval = OK;
-     int		c;
  
      sname = home_replace_save(NULL, name);
!     if (sname != NULL)
! 	name = sname;
!     while (*name != NUL)
!     {
! #ifdef FEAT_MBYTE
! 	{
! 	    int l;
  
! 	    if (has_mbyte && (l = (*mb_ptr2len)(name)) > 1)
! 	    {
! 		/* copy a multibyte char */
! 		while (--l >= 0)
! 		{
! 		    if (putc(*name, fd) != *name)
! 			retval = FAIL;
! 		    ++name;
! 		}
! 		continue;
! 	    }
! 	}
! #endif
! 	c = *name++;
! 	if (c == '\\' && (*flagp & SSOP_SLASH))
! 	    /* change a backslash to a forward slash */
! 	    c = '/';
! 	else if ((vim_strchr(escape_chars, c) != NULL
! #ifdef BACKSLASH_IN_FILENAME
! 		    && c != '\\'
! #endif
! 		 ) || c == '#' || c == '%')
! 	{
! 	    /* escape a special character with a backslash */
! 	    if (putc('\\', fd) != '\\')
! 		retval = FAIL;
! 	}
! 	if (putc(c, fd) != c)
! 	    retval = FAIL;
      }
      vim_free(sname);
      return retval;
  }
  
--- 10717,10748 ----
      unsigned	*flagp;
  {
      char_u	*sname;
+     char_u	*p;
      int		retval = OK;
  
      sname = home_replace_save(NULL, name);
!     if (sname == NULL)
! 	return FAIL;
  
!     if (*flagp & SSOP_SLASH)
!     {
! 	/* change all backslashes to forward slashes */
! 	for (p = sname; *p != NUL; mb_ptr_adv(p))
! 	    if (*p == '\\')
! 		*p = '/';
      }
+ 
+     /* escapse special characters */
+     p = vim_strsave_fnameescape(sname, FALSE);
      vim_free(sname);
+     if (p == NULL)
+ 	return FAIL;
+ 
+     /* write the result */
+     if (fputs((char *)p, fd) < 0)
+ 	retval = FAIL;
+ 
+     vim_free(p);
      return retval;
  }
  
*** ../vim-7.3.024/src/version.c	2010-10-13 16:44:17.000000000 +0200
--- src/version.c	2010-10-13 17:49:15.000000000 +0200
***************
*** 716,717 ****
--- 716,719 ----
  {   /* Add new patch number below this line */
+ /**/
+     25,
  /**/

-- 
"Time flies like an arrow".  So I put an arrow on my desk, now
awaiting one of these time flies showing up.

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
