From f4e4b1ac447fd571056049ad24ba042fa46dba6c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 27 Jun 2010 17:38:08 -0700 Subject: [PATCH] Fix multipart/mixed parsing regression introduced by acffe8ef5. [#79] --- lib/rack/utils.rb | 6 ------ test/multipart/mixed_files | 21 +++++++++++++++++++++ test/spec_utils.rb | 8 ++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 test/multipart/mixed_files diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index bc60cd1..3748392 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -571,12 +571,6 @@ module Rack data = {:filename => filename, :type => content_type, :name => name, :tempfile => body, :head => head} - elsif !filename && content_type - body.rewind - - # Generic multipart cases, not coming from a form - data = {:type => content_type, - :name => name, :tempfile => body, :head => head} else data = body end diff --git a/test/multipart/mixed_files b/test/multipart/mixed_files new file mode 100644 index 0000000..624d804 --- /dev/null +++ b/test/multipart/mixed_files @@ -0,0 +1,21 @@ +--AaB03x +Content-Disposition: form-data; name="foo" + +bar +--AaB03x +Content-Disposition: form-data; name="files" +Content-Type: multipart/mixed, boundary=BbC04y + +--BbC04y +Content-Disposition: attachment; filename="file.txt" +Content-Type: text/plain + +contents +--BbC04y +Content-Disposition: attachment; filename="flowers.jpg" +Content-Type: image/jpeg +Content-Transfer-Encoding: binary + +contents +--BbC04y-- +--AaB03x-- diff --git a/test/spec_utils.rb b/test/spec_utils.rb index 822058b..d9d073b 100644 --- a/test/spec_utils.rb +++ b/test/spec_utils.rb @@ -449,6 +449,14 @@ describe Rack::Utils::Multipart do params.keys.should.not.include "files" end + should "parse multipart/mixed" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:mixed_files)) + params = Rack::Utils::Multipart.parse_multipart(env) + params["foo"].should.equal "bar" + params["files"].should.be.instance_of String + params["files"].size.should.equal 252 + end + should "parse IE multipart upload and clean up filename" do env = Rack::MockRequest.env_for("/", multipart_fixture(:ie)) params = Rack::Utils::Multipart.parse_multipart(env) -- 1.7.1