Skip to content
Browse files

escape backticks on env vars too

  • Loading branch information...
1 parent 8f3be12 commit c262333257301498bdc3772d150de3921346e9f9 @pedro pedro committed with
Showing with 6 additions and 1 deletion.
  1. +2 −1 lib/rush/box.rb
  2. +4 −0 spec/box_spec.rb
View
3 lib/rush/box.rb
@@ -82,7 +82,8 @@ def command_with_environment(command, env) # :nodoc:
return command unless env
vars = env.map do |key, value|
- "export #{key}=\"#{value.to_s.gsub('"', '\\"')}\""
+ escaped = value.to_s.gsub('"', '\\"').gsub('`', '\\\`')
+ "export #{key}=\"#{escaped}\""
end
vars.push(command).join("\n")
end
View
4 spec/box_spec.rb
@@ -45,6 +45,10 @@
@box.command_with_environment('cmd', { :a => 'a"b' }).should == "export a=\"a\\\"b\"\ncmd"
end
+ it "escapes backticks on environment variables" do
+ @box.command_with_environment('cmd', { :a => 'a`b' }).should == "export a=\"a\\\`b\"\ncmd"
+ end
+
it "converts environment variables to_s" do
@box.command_with_environment('cmd', { :a => nil, :b => 123 }).should == "export a=\"\"\nexport b=\"123\"\ncmd"
end

0 comments on commit c262333

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