Commit 00c0daf4 by Jon Yurek

Don't use single-quote to quote windows command lines.

parent ba697508
......@@ -62,12 +62,19 @@ module Paperclip
def shell_quote(string)
return "" if string.nil? or string.blank?
if self.class.unix?
string.split("'").map{|m| "'#{m}'" }.join("\\'")
else
%{"#{string}"}
end
end
def bit_bucket
return "2>NUL" unless File.exist?("/dev/null")
"2>/dev/null"
self.class.unix? ? "2>/dev/null" : "2>NUL"
end
def self.unix?
File.exist?("/dev/null")
end
end
end
......@@ -3,6 +3,7 @@ require 'test/helper'
class CommandLineTest < Test::Unit::TestCase
def setup
Paperclip::CommandLine.path = nil
File.stubs(:exist?).with("/dev/null").returns(true)
end
should "take a command and parameters and produce a shell command for bash" do
......@@ -24,6 +25,15 @@ class CommandLineTest < Test::Unit::TestCase
assert_equal "convert 'a.jpg' 'b.png'", cmd.command
end
should "quote command line options differently if we're on windows" do
File.stubs(:exist?).with("/dev/null").returns(false)
cmd = Paperclip::CommandLine.new("convert",
":one :{two}",
:one => "a.jpg",
:two => "b.png")
assert_equal 'convert "a.jpg" "b.png"', cmd.command
end
should "be able to quote and interpolate dangerous variables" do
cmd = Paperclip::CommandLine.new("convert",
":one :two",
......@@ -32,6 +42,15 @@ class CommandLineTest < Test::Unit::TestCase
assert_equal "convert '`rm -rf`.jpg' 'ha'\\''ha.png'", cmd.command
end
should "be able to quote and interpolate dangerous variables even on windows" do
File.stubs(:exist?).with("/dev/null").returns(false)
cmd = Paperclip::CommandLine.new("convert",
":one :two",
:one => "`rm -rf`.jpg",
:two => "ha'ha.png")
assert_equal %{convert "`rm -rf`.jpg" "ha'ha.png"}, cmd.command
end
should "add redirection to get rid of stderr in bash" do
File.stubs(:exist?).with("/dev/null").returns(true)
cmd = Paperclip::CommandLine.new("convert",
......@@ -96,4 +115,14 @@ class CommandLineTest < Test::Unit::TestCase
Paperclip.expects(:log).with("convert a.jpg b.png")
cmd.run
end
should "detect that the system is unix or windows based on presence of /dev/null" do
File.stubs(:exist?).returns(true)
assert Paperclip::CommandLine.unix?
end
should "detect that the system is not unix or windows based on absence of /dev/null" do
File.stubs(:exist?).returns(false)
assert ! Paperclip::CommandLine.unix?
end
end
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