Bram Moolenaar wrote:
Alexey I. Froloff wrote:

* Bram Moolenaar <Bram@> [060808 22:52]:
!       call system(a:cmd . " '" . nmt . "'")
This patch is evil (>:-E~~~).  Better add shellescape() function
to Vim and properly escape argument.

Well, at least it's a lot better than what it was.  I know it wasn't
perfect.

Patch attached.  I'm not sure if I handle WIN/UNIX defines
properly, also I don't know how to shell-escape string on DOS/WIN
platforms, algorithm was borrowed from php's escapeshellarg()
function.  This function will do nothing on "nonsupported"
platforms.

P.S. In UNIX string is surrounded by single quotes and all single
quotes in string replaced with quote-backslash-quote-quote.  On
DOS/WIN it surrounds string with double quotes and replaces
doublequotes and percents to space.

Makes sense for Unix.  I don't know about MS-DOS/WIN, may depend on the
$SHELL used.  Perhaps 'shellslash' may also need to be considered.

IIRC, in Windows percent signs should be doubled (which requires the same
kind of fancy-footwork as Vim's \ or ^V in the case of recursion), except
in the names of environment %STRINGS% to be resolved by the shell.
(Dos/Windows uses %NAME% where Unix uses $NAME or ${NAME}). I'm not sure
about how to quote double quotes.


A patch for the documentation is missing, this is required to see what
the intention of shellescape() is.


Best regards,
Tony.

Reply via email to