Commit 20e9559a by Jon Yurek

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

parent 3f1390a6
...@@ -112,16 +112,20 @@ module Paperclip ...@@ -112,16 +112,20 @@ module Paperclip
command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr] command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr]
Paperclip.log(command) if Paperclip.options[:log_command] Paperclip.log(command) if Paperclip.options[:log_command]
output = `#{command}` begin
output = `#{command}`
if $?.exitstatus == 127 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 raise CommandNotFoundError
end end
unless expected_outcodes.include?($?.exitstatus)
raise PaperclipCommandLineError,
"Error while running #{cmd}. Expected return code to be #{expected_outcodes.join(", ")} but was #{$?.exitstatus}",
output
end
output output
end end
......
...@@ -63,7 +63,7 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -63,7 +63,7 @@ class PaperclipTest < Test::Unit::TestCase
end end
context "Calling Paperclip.run when the command is not found" do 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 begin
assert_raises(Paperclip::CommandNotFoundError) do assert_raises(Paperclip::CommandNotFoundError) do
`ruby -e 'exit 127'` # Stub $?.exitstatus to be 127, i.e. Command Not Found. `ruby -e 'exit 127'` # Stub $?.exitstatus to be 127, i.e. Command Not Found.
...@@ -74,6 +74,12 @@ class PaperclipTest < Test::Unit::TestCase ...@@ -74,6 +74,12 @@ class PaperclipTest < Test::Unit::TestCase
`ruby -e 'exit 0'` # Unstub $?.exitstatus `ruby -e 'exit 0'` # Unstub $?.exitstatus
end end
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 end
should "prevent dangerous characters in the command via quoting" do 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