Ticket #21 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Merb::Controller doesn't parse form fields in multipart uploads right

Reported by: lu..@slantwisedesign.com Assigned to: somebody
Priority: major Milestone:
Component: Views Keywords:
Cc:

Description

When the request is a multipart POST, merb uses different logic for parsing the form fields, but what ends up happening is that they aren't parsed consistently with regular POST or GET requests.

Examples:

GET and regular POST request:

foo=bar&test[abc]=xyz&test[123]=baz =>

{"foo"=>"bar", "test"=>{"abc"=>"xyz", "123"=>"baz"}}

Multipart POST:

(these are examples from my test program)

commit=upload
media_item[description]=test
media_item[file_type] = Image
media_item[uploaded_data] = a file name
{"commit"=>"Upload", "action"=>"upload", "media_item[uploaded_data]"=>{"name"=>"media_item[uploaded_data]", "type"=>"image/jpeg", "tempfile"=>#<File:/tmp/Merb25539-0>, "filename"=>"Photo 3.jpg"}, "controller"=>"upload", "media_item[file_type]"=>"Image", "media_item[description]"=>"test"}

As you can see, the media_item parameters are not grouped like they should be.

I think it comes down to this logic in the Merb::Controller class:

          if name =~ /(.*)?\[\]/
            (querystring[$1] ||= []) << attrs
          else  
            querystring[name]=attrs if name
          end

First of all, that regexp is wrong, so the else branch is always executed.

Second, I don't think this will handle the case where there are multiple nestings: foo[bar][baz].

Sorry for lack of a test case, I wanted to get this debugged and submitted before I leave work today.

Attachments

multipart-specs.patch (2.5 kB) - added by lu..@slantwisedesign.com on 03/13/07 12:07:18.
Specs for multipart form uploads

Change History

03/13/07 12:07:18 changed by lu..@slantwisedesign.com

  • attachment multipart-specs.patch added.

Specs for multipart form uploads

03/13/07 12:08:23 changed by lu..@slantwisedesign.com

Here's a couple specs for multipart form uploads.

One of them (the simple case where there is a file but nothing else in the form post) passes, but the other two fail.

03/18/07 19:56:33 changed by e.@brainspl.at

  • status changed from new to closed.
  • resolution set to fixed.

(In [200]) completely refactored multipart form parsing to work properly with how folks expect, speed up parsing by 60%, added multipart.rb for specs. closes #21