rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
* Fix for multipart parsing regression
@ 2010-07-04 22:06 Jeremy Kemper
  0 siblings, 0 replies; only message in thread
From: Jeremy Kemper @ 2010-07-04 22:06 UTC (permalink / raw)
  To: rack-devel

Rack 1.2.1 raises an exception when parsing a multipart/mixed request.
acffe8ef5 introduced the regression. Fix and test:
http://github.com/jeremy/rack/commit/f4e4b1a

From f4e4b1ac447fd571056049ad24ba042fa46dba6c Mon Sep 17 00:00:00 2001
From: Jeremy Kemper <jeremy@bitsweat.net>
Date: Sun, 27 Jun 2010 17:38:08 -0700
Subject: [PATCH] Fix multipart/mixed parsing regression introduced by acffe8ef5.

[#79]
---
 lib/rack/utils.rb          |    6 ------
 test/multipart/mixed_files |   21 +++++++++++++++++++++
 test/spec_utils.rb         |    8 ++++++++
 3 files changed, 29 insertions(+), 6 deletions(-)
 create mode 100644 test/multipart/mixed_files

diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb
index bc60cd1..3748392 100644
--- a/lib/rack/utils.rb
+++ b/lib/rack/utils.rb
@@ -571,12 +571,6 @@ module Rack

               data = {:filename => filename, :type => content_type,
                       :name => name, :tempfile => body, :head => head}
-            elsif !filename && content_type
-              body.rewind
-
-              # Generic multipart cases, not coming from a form
-              data = {:type => content_type,
-                      :name => name, :tempfile => body, :head => head}
             else
               data = body
             end
diff --git a/test/multipart/mixed_files b/test/multipart/mixed_files
new file mode 100644
index 0000000..624d804
--- /dev/null
+++ b/test/multipart/mixed_files
@@ -0,0 +1,21 @@
+--AaB03x
+Content-Disposition: form-data; name="foo"
+
+bar
+--AaB03x
+Content-Disposition: form-data; name="files"
+Content-Type: multipart/mixed, boundary=BbC04y
+
+--BbC04y
+Content-Disposition: attachment; filename="file.txt"
+Content-Type: text/plain
+
+contents
+--BbC04y
+Content-Disposition: attachment; filename="flowers.jpg"
+Content-Type: image/jpeg
+Content-Transfer-Encoding: binary
+
+contents
+--BbC04y--
+--AaB03x--
diff --git a/test/spec_utils.rb b/test/spec_utils.rb
index 822058b..d9d073b 100644
--- a/test/spec_utils.rb
+++ b/test/spec_utils.rb
@@ -449,6 +449,14 @@ describe Rack::Utils::Multipart do
     params.keys.should.not.include "files"
   end

+  should "parse multipart/mixed" do
+    env = Rack::MockRequest.env_for("/", multipart_fixture(:mixed_files))
+    params = Rack::Utils::Multipart.parse_multipart(env)
+    params["foo"].should.equal "bar"
+    params["files"].should.be.instance_of String
+    params["files"].size.should.equal 252
+  end
+
   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.7.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-07-04 22:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-04 22:06 Fix for multipart parsing regression Jeremy Kemper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).