Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Paperclip content type validation uses wrong encoding in file command on jruby #1702

Closed
mmustala opened this issue Nov 19, 2014 · 2 comments
Closed

Comments

@mmustala
Copy link

I have recently moved my project from MRI ruby to JRuby. At that time I needed to change my backticks calls to encode the ruby strings into ascii-8bit when passing it into the call to ensure that the correct file is found for example.

`file -b --mime-type #{path.encode('ASCII-8BIT').shellescape}`.try(:strip)

Now I noticed that when Paperclip 4.2.0 (and earlier versions) tries to validate the content type of an attachment whose file name contains utf-8 characters like Öäå the file name goes in with a wrong encoding. The error message is

Command :: file -b --mime '/tmp/ea_Neliö20141119-12290-a5imen'
[paperclip] Error while determining content type: Command 'file -b --mime '/tmp/ea_Neliö20141119-12290-a5imen'' returned 1. Expected 0
Here is the command output:
ERROR: cannot open `/tmp/ea_Neliö20141119-12290-a5imen' (No such file or directory)

I'm running the application on Ubuntu in development and Debian in production.

I would love to offer a patch for this but finding the correct line to fix is not so easy. The way validations are working in Rails seems to be magic.

@mmustala
Copy link
Author

lib/paperclip/file_command_content_type_detector.rb calls

Paperclip.run("file", "-b --mime :file", :file => @filename)

which instead calls

Cocaine::CommandLine.new(cmd, arguments, local_options).run(interpolation_values)

This probably is best to fix in Cocaine #run method where the interpolation_values hash values should be encoded if using jruby and unix os.

@tute
Copy link
Contributor

tute commented May 16, 2015

Thanks @mmustala! Thanks for your input and for reporting this issue to the other projects.

@tute tute closed this as completed May 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants