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