Browse files

Fixed handling of multipart fields that have Content-Type but are not…

… files.

rack@acffe8e
  • Loading branch information...
1 parent a0432d9 commit 502a1bfe392c4266c70ff7944e0a1f9e814451b8 Janne Hietamaki committed with josh Dec 2, 2010
Showing with 8 additions and 2 deletions.
  1. +1 −1 lib/rack/utils.rb
  2. +5 −0 test/multipart/text
  3. +2 −1 test/spec_utils.rb
View
2 lib/rack/utils.rb
@@ -600,7 +600,7 @@ def self.parse_multipart(env)
data = {:filename => filename, :type => content_type,
:name => name, :tempfile => body, :head => head}
- elsif !filename && content_type
+ elsif !filename && content_type && !body.instance_of?(String)
body.rewind
# Generic multipart cases, not coming from a form
View
5 test/multipart/text
@@ -3,6 +3,11 @@ Content-Disposition: form-data; name="submit-name"
Larry
--AaB03x
+Content-Disposition: form-data; name="submit-name-with-content"
+Content-Type: text/plain
+
+Berry
+--AaB03x
Content-Disposition: form-data; name="files"; filename="file1.txt"
Content-Type: text/plain
View
3 test/spec_utils.rb
@@ -441,6 +441,7 @@ def multipart_file(name)
env = Rack::MockRequest.env_for("/", multipart_fixture(:text))
params = Rack::Utils::Multipart.parse_multipart(env)
params["submit-name"].should.equal "Larry"
+ params["submit-name-with-content"].should.equal "Berry"
params["files"][:type].should.equal "text/plain"
params["files"][:filename].should.equal "file1.txt"
params["files"][:head].should.equal "Content-Disposition: form-data; " +
@@ -598,7 +599,7 @@ def multipart_file(name)
params = Rack::Utils::Multipart.parse_multipart(env)
params["submit-name"].should.equal "Larry"
params["files"][:filename].should.equal "file1.txt"
- input.read.length.should.equal 197
+ input.read.length.should.equal 307
end
it "builds multipart body" do

0 comments on commit 502a1bf

Please sign in to comment.