Commit 20e9559a by Jon Yurek

Also give a CommandNotFoundError if backtick raises Errno::ENOENT.

parent 3f1390a6
......@@ -112,16 +112,20 @@ module Paperclip
command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr]
Paperclip.log(command) if Paperclip.options[:log_command]
begin
output = `#{command}`
if $?.exitstatus == 127
raise CommandNotFoundError
end
raise CommandNotFoundError if $?.exitstatus == 127
unless expected_outcodes.include?($?.exitstatus)
raise PaperclipCommandLineError,
"Error while running #{cmd}. Expected return code to be #{expected_outcodes.join(", ")} but was #{$?.exitstatus}",
output
end
rescue Errno::ENOENT => e
raise CommandNotFoundError
end
output
end
......
......@@ -63,7 +63,7 @@ class PaperclipTest < Test::Unit::TestCase
end
context "Calling Paperclip.run when the command is not found" do
should "tell you the command isn't there" do
should "tell you the command isn't there if the shell returns 127" do
begin
assert_raises(Paperclip::CommandNotFoundError) do
`ruby -e 'exit 127'` # Stub $?.exitstatus to be 127, i.e. Command Not Found.
......@@ -74,6 +74,12 @@ class PaperclipTest < Test::Unit::TestCase
`ruby -e 'exit 0'` # Unstub $?.exitstatus
end
end
should "tell you the command isn't there if an ENOENT is raised" do
assert_raises(Paperclip::CommandNotFoundError) do
Paperclip.stubs(:"`").raises(Errno::ENOENT)
Paperclip.run("command")
end
end
end
should "prevent dangerous characters in the command via quoting" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment