On Friday, November 2, 2012 at 1:18 AM, Holger Just wrote:
Hi Joseph,On 2012-11-02 04:15, Joseph Holsten wrote:But shellout isn't quoting or escaping (correctly?). I just triedlooking at mixlib-shellout/lib/mixlib/shellout/windows.rb, butclearly I'm out of my depth trying to grok win32/process.Should that command be quoted before it gets to shellout?Should whitespace be escaped instead? Should shellout handle ittransparently?Unfortunately, you can't just quote any whitespace you find inshell_out! anymore as you can't know which space should be quoted(inside the paths) and which shouldn't (between arguments).I personally see two usable alternatives for actually fixing that:1) You state in the documentation that every variable part of a shelledout command should be quoted by the user. For Linux, you could use thebuiltin Shellwords.escape [1] which escapes strings for the Bourneshell. I'm sure there is a similar module for the Windows shellsomewhere. This change then would need to be applied in every invocationof that method.
2) You extend the shell_out! method (and all similar ones) to optionallyaccept an Array as the first argument instead of a String. Each elementin that array would represent a distinguished argument (including theactual executable). Inside shell_out! you can then individually quoteeach argument and safely concat them for execution. That way, eachconsumer of the function can use it in a way to make it much more safewithout having to reason about quotes on each and every invocation.
While I'd tremendously prefer the second option, it has a tiny littledownside as it would still require some thoughts about how to handlepipes (though I honestly don't know if it is supported right now at all)
As a source of inspiration, I'd like to point to the cocaine gem [2]which nicely encapsulates shell outs and handles the basic case in justa few lines of code.
Archive powered by MHonArc 2.6.16.