thoughtbot/paperclip — pull request #1130 by wnm (2013-01-10 13:01:14+00:00)
Title: Special characters in filename raises an error on temp file creation: Paperclip::Errors::NotIdentifiedByImageMagickError

I'm using rails with ckeditor gem, mongoid-paperclip gem, aws-s3 gem in my project. When I try to upload a file that contains special characters, if fails, and raises the error:

Paperclip::Errors::NotIdentifiedByImageMagickError

After some digging I found that the method who fails is in lib/paperclip/geometry_detector_factory.rb line 18:

Paperclip.run("identify", "-format '%wx%h,%[exif:orientation]' :file", :file => "#{path}[0]")

I tried to run the command with two tempfiles in rails console:

One without special characters:

1.9.3p194 :004 > Paperclip.run("identify", "-format %m :file", :file => "/tmp/temp20130110-28658-1epo2cs.png[0]")
Command :: identify -format %m '/tmp/temp20130110-28658-1epo2cs.png[0]'
=> "PNG\n"

and one with special characters:

1.9.3p194 :001 > Paperclip.run("identify", "-format %m :file", :file => "photo:d20130110-24387-18rbumv.png[0]")
Command :: identify -format %m 'photo:d20130110-24387-18rbumv.png[0]'
identify.im6: unable to open image `d20130110-24387-18rbumv.png': No such file or directory @ error/blob.c/OpenBlob/2638.
identify.im6: unable to open file `d20130110-24387-18rbumv.png' @ error/png.c/ReadPNGImage/3667.
Cocaine::ExitStatusError: Command 'identify -format %m :file' returned 1. Expected 0

My pull request just changes every special character into an underscore when the temp file gets created. I don't know paperclip good enough to be sure that nothing breaks because of this. But it seems to work, and all the test passed as well, so...