Permalink
Browse files

Escape output path if it contains a space

  • Loading branch information...
1 parent d22f101 commit 49c2633e1646dc57002a29718540041970916aec @renchap committed Jan 2, 2011
Showing with 16 additions and 1 deletion.
  1. +3 −1 lib/mini_magick.rb
  2. +13 −0 test/image_test.rb
View
4 lib/mini_magick.rb
@@ -250,7 +250,9 @@ def collapse!
def write(output_to)
if output_to.kind_of?(String) || !output_to.respond_to?(:write)
FileUtils.copy_file @path, output_to
- run_command "identify", output_to # Verify that we have a good image
+ # We need to escape the output path if it contains a space
+ escaped_output_to = output_to.to_s.gsub(' ', '\\ ')
+ run_command "identify", escaped_output_to # Verify that we have a good image
else # stream
File.open(@path, "rb") do |f|
f.binmode
View
13 test/image_test.rb
@@ -71,6 +71,19 @@ def test_image_write
image.destroy!
end
+ def test_image_write_with_space_in_output_path
+ output_path = "test output.gif"
+ begin
+ image = Image.new(SIMPLE_IMAGE_PATH)
+ image.write output_path
+
+ assert File.exists?(output_path)
+ ensure
+ File.delete output_path
+ end
+ image.destroy!
+ end
+
def test_image_write_with_stream
stream = StringIO.new
image = Image.open(SIMPLE_IMAGE_PATH)

0 comments on commit 49c2633

Please sign in to comment.