summary refs log tree commit
diff options
context:
space:
mode:
authorJames Tucker <jftucker@gmail.com>2014-08-22 08:37:33 -0400
committerJames Tucker <jftucker@gmail.com>2014-08-22 08:37:33 -0400
commit366c1242a227475eb74edfe39e7083569532ea15 (patch)
tree1d307a17b922e4da15626e2476586545c309bfea
parente4e4c397e89c026f9c23500cf7fc14ccdb756010 (diff)
parent7e7cd1b28a5d50433afd308f821a0459bf686755 (diff)
downloadrack-366c1242a227475eb74edfe39e7083569532ea15.tar.gz
Merge pull request #725 from olistik/features/tempfile-extension
Preserves extension in the created tempfile
-rw-r--r--lib/rack/multipart/parser.rb3
-rw-r--r--test/spec_multipart.rb6
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)