Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActionDispatch::Http:Parameters force encoding of all params but filename of an uploaded file

#6470

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.

Reported by Franck · February 25th, 2011 @ 03:37 PM

State: new
Milestone: none
Assigned to: nobody
Importance: none