diff options
author | James Tucker <jftucker@gmail.com> | 2014-07-18 16:07:27 -0700 |
---|---|---|
committer | James Tucker <jftucker@gmail.com> | 2014-07-18 16:07:27 -0700 |
commit | 9269d22c56762076e3b775ea65ec1d40494d2402 (patch) | |
tree | d4345fa0f819413a13d6cc82bcc85d905de531de | |
parent | 83155c586521455b43a9b05523b0e6d5318ba086 (diff) | |
download | rack-9269d22c56762076e3b775ea65ec1d40494d2402.tar.gz |
support empty string multipart filename
Closes #702. Enables support for IE11.
-rw-r--r-- | lib/rack/multipart/parser.rb | 4 | ||||
-rw-r--r-- | test/multipart/ie11 | 6 | ||||
-rw-r--r-- | test/spec_multipart.rb | 22 |
3 files changed, 29 insertions, 3 deletions
diff --git a/lib/rack/multipart/parser.rb b/lib/rack/multipart/parser.rb index 22f9734b..324c7d8c 100644 --- a/lib/rack/multipart/parser.rb +++ b/lib/rack/multipart/parser.rb @@ -116,6 +116,10 @@ module Rack name = filename end + if filename && filename.empty? + filename = name + end + if filename (@env['rack.tempfiles'] ||= []) << body = Tempfile.new("RackMultipart") body.binmode if body.respond_to?(:binmode) diff --git a/test/multipart/ie11 b/test/multipart/ie11 new file mode 100644 index 00000000..6c3da47f --- /dev/null +++ b/test/multipart/ie11 @@ -0,0 +1,6 @@ +--AaB03x
+Content-Disposition: form-data; name="files"; filename=""
+Content-Type: text/plain
+
+contents
+--AaB03x--
diff --git a/test/spec_multipart.rb b/test/spec_multipart.rb index 2acb6e0d..959a5cff 100644 --- a/test/spec_multipart.rb +++ b/test/spec_multipart.rb @@ -230,12 +230,15 @@ describe Rack::Multipart do params["files"][:tempfile].read.should.equal "contents" end - should "not include file params if no file was selected" do + # n.b. this case used to be "do not include", but because ie11 now does this + # for selected files, that can no longer be done. It was decided that not + # losing data is better, and no browser is documented with this behavior. + should "include file params if no file was selected" do env = Rack::MockRequest.env_for("/", multipart_fixture(:none)) params = Rack::Multipart.parse_multipart(env) params["submit-name"].should.equal "Larry" - params["files"].should.equal nil - params.keys.should.not.include "files" + params["files"].should.not.equal nil + params.keys.should.include "files" end should "parse multipart/mixed" do @@ -267,6 +270,19 @@ describe Rack::Multipart do params["files"][:tempfile].read.should.equal "contents" end + should "parse IE11 multipart upload" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:ie11)) + params = Rack::Multipart.parse_multipart(env) + params["files"][:type].should.equal "text/plain" + params["files"][:filename].should.equal "files" + params["files"][:head].should.equal "Content-Disposition: form-data; " + + "name=\"files\"; " + + 'filename=""' + + "\r\nContent-Type: text/plain\r\n" + params["files"][:name].should.equal "files" + params["files"][:tempfile].read.should.equal "contents" + end + should "parse filename and modification param" do env = Rack::MockRequest.env_for("/", multipart_fixture(:filename_and_modification_param)) params = Rack::Multipart.parse_multipart(env) |