From 3974f6ab4ecf2942b8b3ebf07e75d1dfbe783188 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 20 Jan 2009 12:24:50 -0600 Subject: [PATCH] Don't create an empty tempfile if no file was uploaded --- lib/rack/utils.rb | 2 +- test/multipart/empty | 9 +++++++++ test/spec_rack_utils.rb | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletions(-) create mode 100644 test/multipart/empty diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index 6017d0e..902fab6 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -307,7 +307,7 @@ module Rack data = body end - if name + if name && body.length > 0 if name =~ /\[\]\z/ params[name] ||= [] params[name] << data diff --git a/test/multipart/empty b/test/multipart/empty new file mode 100644 index 0000000..d66f473 --- /dev/null +++ b/test/multipart/empty @@ -0,0 +1,9 @@ +--AaB03x +Content-Disposition: form-data; name="submit-name" + +Larry +--AaB03x +Content-Disposition: form-data; name="files"; filename="" + + +--AaB03x-- diff --git a/test/spec_rack_utils.rb b/test/spec_rack_utils.rb index f16ac4c..721dc24 100644 --- a/test/spec_rack_utils.rb +++ b/test/spec_rack_utils.rb @@ -184,6 +184,13 @@ context "Rack::Utils::Multipart" do params["files"][:tempfile].read.length.should.equal 26473 end + specify "should not create empty tempfiles if no file was uploaded" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:empty)) + params = Rack::Utils::Multipart.parse_multipart(env) + params["submit-name"].should.equal "Larry" + params["files"].should.equal nil + end + specify "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.6.0.4