Skip to content
Browse files

Quote blank command line values.

  • Loading branch information...
1 parent 87c9625 commit a2d01c4532290b7267c1d99bfdd7165413d2dbf3 @viseztrance viseztrance committed Jan 15, 2012
Showing with 11 additions and 2 deletions.
  1. +2 −2 lib/cocaine/command_line.rb
  2. +9 −0 spec/cocaine/command_line_spec.rb
View
4 lib/cocaine/command_line.rb
@@ -78,9 +78,9 @@ def interpolation(vars, key)
end
def shell_quote(string)
- return "" if string.nil? or string.empty?
@mike-burns
thoughtbot, inc. member
mike-burns added a note Jan 20, 2012

Instead of this escape continuation, how about using an elsif?

@viseztrance
viseztrance added a note Jan 20, 2012

I think you're reffering to something like this:

def shell_quote(string)
  if string.nil?
    ""
  elsif self.class.unix?
    if string.empty?
      "''"
    else
      string.split("'").map{|m| "'#{m}'" }.join("\\'")
    end
  else
    %{"#{string}"}
  end
end

Personally I'm hesitant on refactoring something on my first commit, that's why I tried to keep it as short as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ return "" if string.nil?
if self.class.unix?
- string.split("'").map{|m| "'#{m}'" }.join("\\'")
+ string.empty? ? "''" : string.split("'").map{|m| "'#{m}'" }.join("\\'")
else
%{"#{string}"}
end
View
9 spec/cocaine/command_line_spec.rb
@@ -65,6 +65,15 @@
cmd.command.should == %{convert "`rm -rf`.jpg" "ha'ha.png"}
end
+ it "quotes blank values into the command line's parameters" do
+ cmd = Cocaine::CommandLine.new("curl",
+ "-X POST -d :data :url",
+ :data => "",
+ :url => "http://localhost:9000",
+ :swallow_stderr => false)
+ cmd.command.should == "curl -X POST -d '' 'http://localhost:9000'"
+ end
+
it "allows colons in parameters" do
cmd = Cocaine::CommandLine.new("convert", "'a.jpg' xc:black 'b.jpg'", :swallow_stderr => false)
cmd.command.should == "convert 'a.jpg' xc:black 'b.jpg'"

0 comments on commit a2d01c4

Please sign in to comment.
Something went wrong with that request. Please try again.