1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
10 Patch 7.3.445 (after 7.3.443)
11 Problem: Can't properly escape commands for cmd.exe.
12 Solution: Default 'shellxquote' to '('. Append ')' to make '(command)'.
13 No need to use "/s" for 'shellcmdflag'.
14 Files: src/misc2.c, src/option.c, src/os_win32.c
17 *** ../vim-7.3.444/src/misc2.c 2012-01-20 17:15:47.000000000 +0100
18 --- src/misc2.c 2012-02-16 05:34:37.000000000 +0100
24 ! STRCAT(ncmd, p_sxq);
25 retval = mch_call_shell(ncmd, opt);
32 ! /* When 'shellxquote' is ( append ).
33 ! * When 'shellxquote' is "( append )". */
34 ! STRCAT(ncmd, STRCMP(p_sxq, "(") == 0 ? (char_u *)")"
35 ! : STRCMP(p_sxq, "\"(") == 0 ? (char_u *)")\""
37 retval = mch_call_shell(ncmd, opt);
40 *** ../vim-7.3.444/src/option.c 2012-02-12 23:23:25.000000000 +0100
41 --- src/option.c 2012-02-19 18:08:48.000000000 +0100
44 * my path/to/echo" "my args to echo
47 ! * To avoid this, use the /s argument in addition to /c to force the
48 ! * stripping behavior, and also set shellxquote to automatically
49 ! * surround the entire command in quotes (which get stripped as
53 - /* Set shellxquote default to add the quotes to be stripped. */
54 idx3 = findoption((char_u *)"sxq");
55 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
57 ! p_sxq = (char_u *)"\"";
58 options[idx3].def_val[VI_DEFAULT] = p_sxq;
61 - /* Set shellcmdflag default to always strip the quotes, note the order
62 - * between /s and /c is important or cmd.exe will treat the /s as part
63 - * of the command to be executed. */
64 idx3 = findoption((char_u *)"shcf");
65 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
67 ! p_shcf = (char_u *)"/s /c";
68 options[idx3].def_val[VI_DEFAULT] = p_shcf;
72 * my path/to/echo" "my args to echo
75 ! * To avoid this, set shellxquote to surround the command in
76 ! * parenthesis. This appears to make most commands work, without
77 ! * breaking commands that worked previously, such as
78 ! * '"path with spaces/cmd" "a&b"'.
80 idx3 = findoption((char_u *)"sxq");
81 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
83 ! p_sxq = (char_u *)"(";
84 options[idx3].def_val[VI_DEFAULT] = p_sxq;
87 idx3 = findoption((char_u *)"shcf");
88 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
90 ! p_shcf = (char_u *)"/c";
91 options[idx3].def_val[VI_DEFAULT] = p_shcf;
94 *** ../vim-7.3.444/src/os_win32.c 2011-08-27 15:10:00.000000000 +0200
95 --- src/os_win32.c 2012-02-19 18:11:23.000000000 +0100
98 newcmd = lalloc(cmdlen, TRUE);
101 ! char_u *cmdbase = (*cmd == '"' ? cmd + 1 : cmd);
103 if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5]))
107 newcmd = lalloc(cmdlen, TRUE);
110 ! char_u *cmdbase = cmd;
112 + /* Skip a leading ", ( and "(. */
113 + if (*cmdbase == '"' )
115 + if (*cmdbase == '(')
117 if ((STRNICMP(cmdbase, "start", 5) == 0) && vim_iswhite(cmdbase[5]))
122 * empty, keep the double quotes around the command.
123 * Otherwise remove the double quotes, they aren't needed
124 * here, because we don't use a shell to run the command. */
125 ! if (*cmd == '"' && *p_sxq == NUL)
128 ! STRCPY(newcmd + 1, cmdbase);
132 ! STRCPY(newcmd, cmdbase);
133 ! if (*cmd == '"' && *newcmd != NUL)
134 ! newcmd[STRLEN(newcmd) - 1] = NUL;
139 * empty, keep the double quotes around the command.
140 * Otherwise remove the double quotes, they aren't needed
141 * here, because we don't use a shell to run the command. */
144 ! if (STRNCMP(cmd, p_sxq, cmd - cmdbase) != 0)
146 ! STRCPY(newcmd, cmd);
152 ! STRCPY(newcmd, cmdbase);
153 ! /* Remove a trailing ", ) and )" if they have a match
154 ! * at the start of the command. */
155 ! p = newcmd + STRLEN(newcmd);
156 ! if (p > newcmd && p[-1] == '"' && *cmd == '"')
158 ! if (p > newcmd && p[-1] == ')'
159 ! && (*cmd =='(' || cmd[1] == '('))
167 * inherit our handles which causes unpleasant dangling swap
168 * files if we exit before the spawned process
170 ! if (CreateProcess (NULL, // Executable name
171 newcmd, // Command to execute
172 NULL, // Process security attributes
173 NULL, // Thread security attributes
175 * inherit our handles which causes unpleasant dangling swap
176 * files if we exit before the spawned process
178 ! if (CreateProcess(NULL, // Executable name
179 newcmd, // Command to execute
180 NULL, // Process security attributes
181 NULL, // Thread security attributes
182 *** ../vim-7.3.444/src/version.c 2012-02-13 00:01:38.000000000 +0100
183 --- src/version.c 2012-02-19 18:01:46.000000000 +0100
187 { /* Add new patch number below this line */
193 hundred-and-one symptoms of being an internet addict:
194 80. At parties, you introduce your spouse as your "service provider."
196 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
197 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
198 \\\ an exciting new programming language -- http://www.Zimbu.org ///
199 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///