Karsten Hopp e97cbc
To: vim_dev@googlegroups.com
Karsten Hopp e97cbc
Subject: Patch 7.3.445
Karsten Hopp e97cbc
Fcc: outbox
Karsten Hopp e97cbc
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp e97cbc
Mime-Version: 1.0
Karsten Hopp e97cbc
Content-Type: text/plain; charset=UTF-8
Karsten Hopp e97cbc
Content-Transfer-Encoding: 8bit
Karsten Hopp e97cbc
------------
Karsten Hopp e97cbc
Karsten Hopp e97cbc
Patch 7.3.445 (after 7.3.443)
Karsten Hopp e97cbc
Problem:    Can't properly escape commands for cmd.exe.
Karsten Hopp e97cbc
Solution:   Default 'shellxquote' to '('.  Append ')' to make '(command)'.
Karsten Hopp e97cbc
	    No need to use "/s" for 'shellcmdflag'.
Karsten Hopp e97cbc
Files:	    src/misc2.c, src/option.c, src/os_win32.c
Karsten Hopp e97cbc
Karsten Hopp e97cbc
Karsten Hopp e97cbc
*** ../vim-7.3.444/src/misc2.c	2012-01-20 17:15:47.000000000 +0100
Karsten Hopp e97cbc
--- src/misc2.c	2012-02-16 05:34:37.000000000 +0100
Karsten Hopp e97cbc
***************
Karsten Hopp e97cbc
*** 3230,3236 ****
Karsten Hopp e97cbc
  	    {
Karsten Hopp e97cbc
  		STRCPY(ncmd, p_sxq);
Karsten Hopp e97cbc
  		STRCAT(ncmd, cmd);
Karsten Hopp e97cbc
! 		STRCAT(ncmd, p_sxq);
Karsten Hopp e97cbc
  		retval = mch_call_shell(ncmd, opt);
Karsten Hopp e97cbc
  		vim_free(ncmd);
Karsten Hopp e97cbc
  	    }
Karsten Hopp e97cbc
--- 3230,3240 ----
Karsten Hopp e97cbc
  	    {
Karsten Hopp e97cbc
  		STRCPY(ncmd, p_sxq);
Karsten Hopp e97cbc
  		STRCAT(ncmd, cmd);
Karsten Hopp e97cbc
! 		/* When 'shellxquote' is ( append ).
Karsten Hopp e97cbc
! 		 * When 'shellxquote' is "( append )". */
Karsten Hopp e97cbc
! 		STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")"
Karsten Hopp e97cbc
! 			   : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
Karsten Hopp e97cbc
! 			   : p_sxq);
Karsten Hopp e97cbc
  		retval = mch_call_shell(ncmd, opt);
Karsten Hopp e97cbc
  		vim_free(ncmd);
Karsten Hopp e97cbc
  	    }
Karsten Hopp e97cbc
*** ../vim-7.3.444/src/option.c	2012-02-12 23:23:25.000000000 +0100
Karsten Hopp e97cbc
--- src/option.c	2012-02-19 18:08:48.000000000 +0100
Karsten Hopp e97cbc
***************
Karsten Hopp e97cbc
*** 3933,3959 ****
Karsten Hopp e97cbc
  	 *   my path/to/echo" "my args to echo
Karsten Hopp e97cbc
  	 * when executed.
Karsten Hopp e97cbc
  	 *
Karsten Hopp e97cbc
! 	 * To avoid this, use the /s argument in addition to /c to force the
Karsten Hopp e97cbc
! 	 * stripping behavior, and also set shellxquote to automatically
Karsten Hopp e97cbc
! 	 * surround the entire command in quotes (which get stripped as
Karsten Hopp e97cbc
! 	 * noted).
Karsten Hopp e97cbc
  	 */
Karsten Hopp e97cbc
- 
Karsten Hopp e97cbc
- 	/* Set shellxquote default to add the quotes to be stripped. */
Karsten Hopp e97cbc
  	idx3 = findoption((char_u *)"sxq");
Karsten Hopp e97cbc
  	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Karsten Hopp e97cbc
  	{
Karsten Hopp e97cbc
! 	    p_sxq = (char_u *)"\"";
Karsten Hopp e97cbc
  	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
Karsten Hopp e97cbc
  	}
Karsten Hopp e97cbc
  
Karsten Hopp e97cbc
- 	/* Set shellcmdflag default to always strip the quotes, note the order
Karsten Hopp e97cbc
- 	 * between /s and /c is important or cmd.exe will treat the /s as part
Karsten Hopp e97cbc
- 	 * of the command to be executed.  */
Karsten Hopp e97cbc
  	idx3 = findoption((char_u *)"shcf");
Karsten Hopp e97cbc
  	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Karsten Hopp e97cbc
  	{
Karsten Hopp e97cbc
! 	    p_shcf = (char_u *)"/s /c";
Karsten Hopp e97cbc
  	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
Karsten Hopp e97cbc
  	}
Karsten Hopp e97cbc
      }
Karsten Hopp e97cbc
--- 3933,3954 ----
Karsten Hopp e97cbc
  	 *   my path/to/echo" "my args to echo
Karsten Hopp e97cbc
  	 * when executed.
Karsten Hopp e97cbc
  	 *
Karsten Hopp e97cbc
! 	 * To avoid this, set shellxquote to surround the command in
Karsten Hopp e97cbc
! 	 * parenthesis.  This appears to make most commands work, without
Karsten Hopp e97cbc
! 	 * breaking commands that worked previously, such as
Karsten Hopp e97cbc
! 	 * '"path with spaces/cmd" "a&b"'.
Karsten Hopp e97cbc
  	 */
Karsten Hopp e97cbc
  	idx3 = findoption((char_u *)"sxq");
Karsten Hopp e97cbc
  	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Karsten Hopp e97cbc
  	{
Karsten Hopp e97cbc
! 	    p_sxq = (char_u *)"(";
Karsten Hopp e97cbc
  	    options[idx3].def_val[VI_DEFAULT] = p_sxq;
Karsten Hopp e97cbc
  	}
Karsten Hopp e97cbc
  
Karsten Hopp e97cbc
  	idx3 = findoption((char_u *)"shcf");
Karsten Hopp e97cbc
  	if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Karsten Hopp e97cbc
  	{
Karsten Hopp e97cbc
! 	    p_shcf = (char_u *)"/c";
Karsten Hopp e97cbc
  	    options[idx3].def_val[VI_DEFAULT] = p_shcf;
Karsten Hopp e97cbc
  	}
Karsten Hopp e97cbc
      }
Karsten Hopp e97cbc
*** ../vim-7.3.444/src/os_win32.c	2011-08-27 15:10:00.000000000 +0200
Karsten Hopp e97cbc
--- src/os_win32.c	2012-02-19 18:11:23.000000000 +0100
Karsten Hopp e97cbc
***************
Karsten Hopp e97cbc
*** 3908,3915 ****
Karsten Hopp e97cbc
  	newcmd = lalloc(cmdlen, TRUE);
Karsten Hopp e97cbc
  	if (newcmd != NULL)
Karsten Hopp e97cbc
  	{
Karsten Hopp e97cbc
! 	    char_u *cmdbase = (*cmd == '"' ? cmd + 1 : cmd);
Karsten Hopp e97cbc
  
Karsten Hopp e97cbc
  	    if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5]))
Karsten Hopp e97cbc
  	    {
Karsten Hopp e97cbc
  		STARTUPINFO		si;
Karsten Hopp e97cbc
--- 3908,3920 ----
Karsten Hopp e97cbc
  	newcmd = lalloc(cmdlen, TRUE);
Karsten Hopp e97cbc
  	if (newcmd != NULL)
Karsten Hopp e97cbc
  	{
Karsten Hopp e97cbc
! 	    char_u *cmdbase = cmd;
Karsten Hopp e97cbc
  
Karsten Hopp e97cbc
+ 	    /* Skip a leading ", ( and "(. */
Karsten Hopp e97cbc
+ 	    if (*cmdbase == '"' )
Karsten Hopp e97cbc
+ 		++cmdbase;
Karsten Hopp e97cbc
+ 	    if (*cmdbase == '(')
Karsten Hopp e97cbc
+ 		++cmdbase;
Karsten Hopp e97cbc
  	    if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5]))
Karsten Hopp e97cbc
  	    {
Karsten Hopp e97cbc
  		STARTUPINFO		si;
Karsten Hopp e97cbc
***************
Karsten Hopp e97cbc
*** 3953,3968 ****
Karsten Hopp e97cbc
  		 * empty, keep the double quotes around the command.
Karsten Hopp e97cbc
  		 * Otherwise remove the double quotes, they aren't needed
Karsten Hopp e97cbc
  		 * here, because we don't use a shell to run the command. */
Karsten Hopp e97cbc
! 		if (*cmd == '"' && *p_sxq == NUL)
Karsten Hopp e97cbc
  		{
Karsten Hopp e97cbc
! 		    newcmd[0] = '"';
Karsten Hopp e97cbc
! 		    STRCPY(newcmd + 1, cmdbase);
Karsten Hopp e97cbc
! 		}
Karsten Hopp e97cbc
! 		else
Karsten Hopp e97cbc
! 		{
Karsten Hopp e97cbc
! 		    STRCPY(newcmd, cmdbase);
Karsten Hopp e97cbc
! 		    if (*cmd == '"' && *newcmd != NUL)
Karsten Hopp e97cbc
! 			newcmd[STRLEN(newcmd) - 1] = NUL;
Karsten Hopp e97cbc
  		}
Karsten Hopp e97cbc
  
Karsten Hopp e97cbc
  		/*
Karsten Hopp e97cbc
--- 3958,3983 ----
Karsten Hopp e97cbc
  		 * empty, keep the double quotes around the command.
Karsten Hopp e97cbc
  		 * Otherwise remove the double quotes, they aren't needed
Karsten Hopp e97cbc
  		 * here, because we don't use a shell to run the command. */
Karsten Hopp e97cbc
! 		if (cmdbase > cmd)
Karsten Hopp e97cbc
  		{
Karsten Hopp e97cbc
! 		    if (STRNCMP(cmd, p_sxq, cmd - cmdbase) != 0)
Karsten Hopp e97cbc
! 		    {
Karsten Hopp e97cbc
! 			STRCPY(newcmd, cmd);
Karsten Hopp e97cbc
! 		    }
Karsten Hopp e97cbc
! 		    else
Karsten Hopp e97cbc
! 		    {
Karsten Hopp e97cbc
! 			char_u *p;
Karsten Hopp e97cbc
! 
Karsten Hopp e97cbc
! 			STRCPY(newcmd, cmdbase);
Karsten Hopp e97cbc
! 			/* Remove a trailing ", ) and )" if they have a match
Karsten Hopp e97cbc
! 			 * at the start of the command. */
Karsten Hopp e97cbc
! 			p = newcmd + STRLEN(newcmd);
Karsten Hopp e97cbc
! 			if (p > newcmd && p[-1] == '"' && *cmd == '"')
Karsten Hopp e97cbc
! 			    *--p = NUL;
Karsten Hopp e97cbc
! 			if (p > newcmd && p[-1] == ')'
Karsten Hopp e97cbc
! 					     && (*cmd =='(' || cmd[1] == '('))
Karsten Hopp e97cbc
! 			    *--p = NUL;
Karsten Hopp e97cbc
! 		    }
Karsten Hopp e97cbc
  		}
Karsten Hopp e97cbc
  
Karsten Hopp e97cbc
  		/*
Karsten Hopp e97cbc
***************
Karsten Hopp e97cbc
*** 3970,3976 ****
Karsten Hopp e97cbc
  		 * inherit our handles which causes unpleasant dangling swap
Karsten Hopp e97cbc
  		 * files if we exit before the spawned process
Karsten Hopp e97cbc
  		 */
Karsten Hopp e97cbc
! 		if (CreateProcess (NULL,	// Executable name
Karsten Hopp e97cbc
  			newcmd,			// Command to execute
Karsten Hopp e97cbc
  			NULL,			// Process security attributes
Karsten Hopp e97cbc
  			NULL,			// Thread security attributes
Karsten Hopp e97cbc
--- 3985,3991 ----
Karsten Hopp e97cbc
  		 * inherit our handles which causes unpleasant dangling swap
Karsten Hopp e97cbc
  		 * files if we exit before the spawned process
Karsten Hopp e97cbc
  		 */
Karsten Hopp e97cbc
! 		if (CreateProcess(NULL,		// Executable name
Karsten Hopp e97cbc
  			newcmd,			// Command to execute
Karsten Hopp e97cbc
  			NULL,			// Process security attributes
Karsten Hopp e97cbc
  			NULL,			// Thread security attributes
Karsten Hopp e97cbc
*** ../vim-7.3.444/src/version.c	2012-02-13 00:01:38.000000000 +0100
Karsten Hopp e97cbc
--- src/version.c	2012-02-19 18:01:46.000000000 +0100
Karsten Hopp e97cbc
***************
Karsten Hopp e97cbc
*** 716,717 ****
Karsten Hopp e97cbc
--- 716,719 ----
Karsten Hopp e97cbc
  {   /* Add new patch number below this line */
Karsten Hopp e97cbc
+ /**/
Karsten Hopp e97cbc
+     445,
Karsten Hopp e97cbc
  /**/
Karsten Hopp e97cbc
Karsten Hopp e97cbc
-- 
Karsten Hopp e97cbc
hundred-and-one symptoms of being an internet addict:
Karsten Hopp e97cbc
80. At parties, you introduce your spouse as your "service provider."
Karsten Hopp e97cbc
Karsten Hopp e97cbc
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp e97cbc
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp e97cbc
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp e97cbc
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///