diff options
author | Janne Hietamaki <janne.hietamaki@leonidasoy.fi> | 2010-12-02 18:36:31 +0200 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2010-12-09 14:06:16 -0600 |
commit | 502a1bfe392c4266c70ff7944e0a1f9e814451b8 (patch) | |
tree | 2a0e3f41b27b7bed2f01f69e4a7ff73c4f584c19 | |
parent | a0432d9371dd6a42234ec47a85ba7649517155a7 (diff) | |
download | rack-502a1bfe392c4266c70ff7944e0a1f9e814451b8.tar.gz |
Fixed handling of multipart fields that have Content-Type but are not files.
https://github.com/rack/rack/commit/acffe8ef5ea6de74fe306f2dd908b7681a21aaad
-rw-r--r-- | lib/rack/utils.rb | 2 | ||||
-rw-r--r-- | test/multipart/text | 5 | ||||
-rw-r--r-- | test/spec_utils.rb | 3 |
3 files changed, 8 insertions, 2 deletions
diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index 0b75cb88..1b1303a3 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -600,7 +600,7 @@ module Rack 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 diff --git a/test/multipart/text b/test/multipart/text index b83d3821..01376d02 100644 --- a/test/multipart/text +++ b/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
diff --git a/test/spec_utils.rb b/test/spec_utils.rb index 79d0f1c1..34b62443 100644 --- a/test/spec_utils.rb +++ b/test/spec_utils.rb @@ -441,6 +441,7 @@ describe Rack::Utils::Multipart do 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 @@ describe Rack::Utils::Multipart do 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 |