diff options
-rw-r--r-- | lib/rack/multipart/parser.rb | 3 | ||||
-rw-r--r-- | test/spec_multipart.rb | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/rack/multipart/parser.rb b/lib/rack/multipart/parser.rb index 22f9734b..0efe0939 100644 --- a/lib/rack/multipart/parser.rb +++ b/lib/rack/multipart/parser.rb @@ -117,7 +117,8 @@ module Rack end if filename - (@env['rack.tempfiles'] ||= []) << body = Tempfile.new("RackMultipart") + extname = ::File.extname(filename) + (@env['rack.tempfiles'] ||= []) << body = Tempfile.new(["RackMultipart", extname]) body.binmode if body.respond_to?(:binmode) end diff --git a/test/spec_multipart.rb b/test/spec_multipart.rb index 2acb6e0d..01e0d814 100644 --- a/test/spec_multipart.rb +++ b/test/spec_multipart.rb @@ -153,6 +153,12 @@ describe Rack::Multipart do params["files"][:tempfile].read.should.equal "contents" end + should "preserve extension in the created tempfile" do + env = Rack::MockRequest.env_for("/", multipart_fixture(:text)) + params = Rack::Multipart.parse_multipart(env) + File.extname(params["files"][:tempfile].path).should.equal ".txt" + end + should "parse multipart upload with text file with no name field" do env = Rack::MockRequest.env_for("/", multipart_fixture(:filename_and_no_name)) params = Rack::Multipart.parse_multipart(env) |