Skip to content

Commit

Permalink
define env vars with double quotes, and escaping the values
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Belo committed Nov 5, 2009
1 parent 353e632 commit ff4a873
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rush/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def command_with_environment(command, env) # :nodoc:
return command unless env

vars = env.map do |key, value|
"export #{key}='#{value}'"
"export #{key}=\"#{value.gsub('"', '\\"')}\""
end
vars.push(command).join("\n")
end
Expand Down
6 changes: 5 additions & 1 deletion spec/box_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
end

it "builds a script of environment variables to prefix the bash command" do
@box.command_with_environment('cmd', { :a => 'b' }).should == "export a='b'\ncmd"
@box.command_with_environment('cmd', { :a => 'b' }).should == "export a=\"b\"\ncmd"
end

it "escapes quotes on environment variables" do
@box.command_with_environment('cmd', { :a => 'a"b' }).should == "export a=\"a\\\"b\"\ncmd"
end

it "sets the environment variables from the provided hash" do
Expand Down

0 comments on commit ff4a873

Please sign in to comment.