To: vim-dev@vim.org Subject: Patch 7.2b.005 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 7.2b.005 Problem: The special character "!" isn't handled properly in shellescape(). (Jan Minar) Solution: Escape "!" when using a "csh" like shell and with shellescape(s, 1). Twice for both. Also escape . Files: src/misc2.c *** ../vim-7.2b.004/src/misc2.c Fri Jul 4 11:43:30 2008 --- src/misc2.c Wed Jul 16 22:40:33 2008 *************** *** 1262,1268 **** * Escape "string" for use as a shell argument with system(). * This uses single quotes, except when we know we need to use double qoutes * (MS-DOS and MS-Windows without 'shellslash' set). ! * Also replace "%", "#" and things like "" when "do_special" is TRUE. * Returns the result in allocated memory, NULL if we have run out. */ char_u * --- 1262,1270 ---- * Escape "string" for use as a shell argument with system(). * This uses single quotes, except when we know we need to use double qoutes * (MS-DOS and MS-Windows without 'shellslash' set). ! * Escape a newline, depending on the 'shell' option. ! * When "do_special" is TRUE also replace "!", "%", "#" and things starting ! * with "<" like "". * Returns the result in allocated memory, NULL if we have run out. */ char_u * *************** *** 1275,1280 **** --- 1277,1289 ---- char_u *d; char_u *escaped_string; int l; + int csh_like; + + /* Only csh and similar shells expand '!' within single quotes. For sh and + * the like we must not put a backslash before it, it will be taken + * literally. If do_special is set the '!' will be escaped twice. + * Csh also needs to have "\n" escaped twice when do_special is set. */ + csh_like = (strstr((char *)gettail(p_sh), "csh") != NULL); /* First count the number of extra bytes required. */ length = (unsigned)STRLEN(string) + 3; /* two quotes and a trailing NUL */ *************** *** 1290,1295 **** --- 1299,1310 ---- # endif if (*p == '\'') length += 3; /* ' => '\'' */ + if (*p == '\n' || (*p == '!' && (csh_like || do_special))) + { + ++length; /* insert backslash */ + if (csh_like && do_special) + ++length; /* insert backslash */ + } if (do_special && find_cmdline_var(p, &l) >= 0) { ++length; /* insert backslash */ *************** *** 1335,1340 **** --- 1350,1363 ---- ++p; continue; } + if (*p == '\n' || (*p == '!' && (csh_like || do_special))) + { + *d++ = '\\'; + if (csh_like && do_special) + *d++ = '\\'; + *d++ = *p++; + continue; + } if (do_special && find_cmdline_var(p, &l) >= 0) { *d++ = '\\'; /* insert backslash */ *** ../vim-7.2b.004/src/version.c Mon Jul 14 23:04:13 2008 --- src/version.c Wed Jul 16 22:31:54 2008 *************** *** 678,679 **** --- 678,681 ---- { /* Add new patch number below this line */ + /**/ + 5, /**/ -- Place mark here ->[ ]<- if you want a dirty monitor. /// 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 ///