This project is archived and is in readonly mode.
ActionDispatch::Http:Parameters force encoding of all params but filename of an uploaded file
Reported by Franck | February 25th, 2011 @ 03:37 PM
I run into a problem when I submit a form with a text field and a filename of an uploaded file both containing special chars.
Tracking down the issue it seems that while ActionDispatch force the encoding of all string paramaters to UTF-8 (see ActionDispatch::Http:Parameters encode_params private method), it does not do at to the filename of the uploaded file.
params is then filled with two different encoding (UTF-8 and ASCII-8BIT) causing an Encoding::CompatibilityError later on Arel-2.0.8 (to_sql.rb visit_Arel_Nodes_Values method).
I monkey patched ActionDispatch::Http:UploadedFile like so and it works :
def initialize(hash)
@original_filename = hash[:filename].force_encoding("UTF-8")
@content_type = hash[:type]
@headers = hash[:head]
@tempfile = hash[:tempfile]
raise(ArgumentError, ':tempfile is required') unless @tempfile
end
My computing skill stop here. I let you guys decide if this is a bug or if I'm doing something wrong.
Comments and changes to this ticket
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>