Ben Fritz wrote:

> I think we should do the auto-escaping, with shellxquote=(, and
> additionally add a help note by :! and system() that "According to the
> Microsoft documentation for cmd.exe, you either need to escape (with a
> ^ character) any of these characters appearing literally in your
> command, or surround them in quotes ("): > ( ) @ ^ |." Should we
> mention that Vim will escape them again, and also escape "?

Yes, I think the use should escape & and | when they appear in a
command.  I haven't verified, but I believe they are illegal in a file
name.

Please try the patch below.  I currently do not have a Windows machine
to try this out.


*** ../vim-7.3.444/src/misc2.c  2012-01-20 17:15:47.000000000 +0100
--- src/misc2.c 2012-02-16 05:34:37.000000000 +0100
***************
*** 3230,3236 ****
            {
                STRCPY(ncmd, p_sxq);
                STRCAT(ncmd, cmd);
!               STRCAT(ncmd, p_sxq);
                retval = mch_call_shell(ncmd, opt);
                vim_free(ncmd);
            }
--- 3230,3240 ----
            {
                STRCPY(ncmd, p_sxq);
                STRCAT(ncmd, cmd);
!               /* When 'shellxquote' is ( append ).
!                * When 'shellxquote' is "( append )". */
!               STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")"
!                          : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
!                          : p_sxq);
                retval = mch_call_shell(ncmd, opt);
                vim_free(ncmd);
            }
*** ../vim-7.3.444/src/option.c 2012-02-12 23:23:25.000000000 +0100
--- src/option.c        2012-02-16 05:31:12.000000000 +0100
***************
*** 3935,3949 ****
         *
         * To avoid this, use the /s argument in addition to /c to force the
         * stripping behavior, and also set shellxquote to automatically
!        * surround the entire command in quotes (which get stripped as
!        * noted).
         */
  
        /* Set shellxquote default to add the quotes to be stripped. */
        idx3 = findoption((char_u *)"sxq");
        if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
        {
!           p_sxq = (char_u *)"\"";
            options[idx3].def_val[VI_DEFAULT] = p_sxq;
        }
  
--- 3935,3949 ----
         *
         * To avoid this, use the /s argument in addition to /c to force the
         * stripping behavior, and also set shellxquote to automatically
!        * surround the entire command in "(cmd)" (the double quotes get
!        * stripped as noted).
         */
  
        /* Set shellxquote default to add the quotes to be stripped. */
        idx3 = findoption((char_u *)"sxq");
        if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
        {
!           p_sxq = (char_u *)"\"(";
            options[idx3].def_val[VI_DEFAULT] = p_sxq;
        }
  
*** ../vim-7.3.444/src/os_win32.c       2011-08-27 15:10:00.000000000 +0200
--- src/os_win32.c      2012-02-16 05:47:36.000000000 +0100
***************
*** 3908,3915 ****
        newcmd = lalloc(cmdlen, TRUE);
        if (newcmd != NULL)
        {
!           char_u *cmdbase = (*cmd == '"' ? cmd + 1 : cmd);
  
            if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5]))
            {
                STARTUPINFO             si;
--- 3908,3920 ----
        newcmd = lalloc(cmdlen, TRUE);
        if (newcmd != NULL)
        {
!           char_u *cmdbase = cmd;
  
+           /* Skip a leading ", ( and "(. */
+           if (*cmdbase == '"' )
+               ++cmdbase;
+           if (*cmdbase == '(')
+               ++cmdbase;
            if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5]))
            {
                STARTUPINFO             si;
***************
*** 3953,3968 ****
                 * empty, keep the double quotes around the command.
                 * Otherwise remove the double quotes, they aren't needed
                 * here, because we don't use a shell to run the command. */
!               if (*cmd == '"' && *p_sxq == NUL)
                {
!                   newcmd[0] = '"';
!                   STRCPY(newcmd + 1, cmdbase);
!               }
!               else
!               {
!                   STRCPY(newcmd, cmdbase);
!                   if (*cmd == '"' && *newcmd != NUL)
!                       newcmd[STRLEN(newcmd) - 1] = NUL;
                }
  
                /*
--- 3958,3983 ----
                 * empty, keep the double quotes around the command.
                 * Otherwise remove the double quotes, they aren't needed
                 * here, because we don't use a shell to run the command. */
!               if (cmdbase > cmd)
                {
!                   if (STRNCMP(cmd, p_sxq, cmd - cmdbase) != 0)
!                   {
!                       STRCPY(newcmd, cmd);
!                   }
!                   else
!                   {
!                       char_u *p;
! 
!                       STRCPY(newcmd, cmdbase);
!                       /* Remove a trailing ", ) and )" if they have a match
!                        * at the start of the command. */
!                       p = newcmd + STRLEN(newcmd);
!                       if (p > newcmd && p[-1] == '"' && *cmd == '"')
!                           *--p = NUL;
!                       if (p > newcmd && p[-1] == ')'
!                                            && (*cmd =='(' || cmd[1] == '('))
!                           *--p = NUL;
!                   }
                }
  
                /*



-- 
hundred-and-one symptoms of being an internet addict:
60. As your car crashes through the guardrail on a mountain road, your first
    instinct is to search for the "back" button.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui