Skip to content

Commit

Permalink
support empty string multipart filename
Browse files Browse the repository at this point in the history
Closes #702.

Enables support for IE11.
  • Loading branch information
raggi committed Jul 18, 2014
1 parent 83155c5 commit 9269d22
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/rack/multipart/parser.rb
Expand Up @@ -116,6 +116,10 @@ def get_current_head_and_filename_and_content_type_and_name_and_body
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)
Expand Down
6 changes: 6 additions & 0 deletions test/multipart/ie11
@@ -0,0 +1,6 @@
--AaB03x
Content-Disposition: form-data; name="files"; filename=""
Content-Type: text/plain

contents
--AaB03x--
22 changes: 19 additions & 3 deletions test/spec_multipart.rb
Expand Up @@ -230,12 +230,15 @@ def rd.length
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
Expand Down Expand Up @@ -267,6 +270,19 @@ def rd.length
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)
Expand Down

0 comments on commit 9269d22

Please sign in to comment.