Permalink
Browse files

1.9 - Ensure all arguments are converted to strings before calling exec

  • Loading branch information...
1 parent 2865f6e commit fbb9c3bf04b63e0121bb1c651fe53c53206cc647 @ileitch ileitch committed Feb 5, 2011
Showing with 6 additions and 2 deletions.
  1. +1 −1 Rakefile
  2. +1 −1 lib/safe_shell.rb
  3. +4 −0 spec/safe_shell_spec.rb
View
2 Rakefile
@@ -6,7 +6,7 @@ begin
Jeweler::Tasks.new do |gem|
gem.name = "safe_shell"
gem.summary = %Q{Safely execute shell commands and get their output.}
- gem.description = %Q{Execute shell commands and get the resulting output, but without the security problems of Rubys backtick operator.}
+ gem.description = %Q{Execute shell commands and get the resulting output, but without the security problems of Ruby's backtick operator.}
gem.email = "pete@notahat.com"
gem.homepage = "http://github.com/envato/safe_shell"
gem.authors = ["Envato", "Ian Leitch", "Pete Yandell"]
View
2 lib/safe_shell.rb
@@ -8,7 +8,7 @@ def self.execute(command, *args)
read_end.close
STDOUT.reopen(new_stdout)
STDERR.reopen(new_stderr)
- exec(command, *args)
+ exec(command, *(args.map { |a| a.to_s }))
end
write_end.close
output = read_end.read
View
4 spec/safe_shell_spec.rb
@@ -18,6 +18,10 @@
$?.exitstatus.should == 1
end
+ it "should handle a Pathname object passed as an argument" do
+ expect { SafeShell.execute("ls", Pathname.new("/tmp")) }.should_not raise_error
+ end
+
context "output redirection" do
before do
File.delete("tmp/output.txt") if File.exists?("tmp/output.txt")

0 comments on commit fbb9c3b

Please sign in to comment.