Skip to content

Instantly share code, notes, and snippets.

@julesfern
Created June 29, 2009 11:55
Show Gist options
  • Select an option

  • Save julesfern/137588 to your computer and use it in GitHub Desktop.

Select an option

Save julesfern/137588 to your computer and use it in GitHub Desktop.
From d1103e9242c4bb55ba4d0c0b52056751200794e4 Mon Sep 17 00:00:00 2001
From: danski <dan@angryamoeba.co.uk>
Date: Mon, 29 Jun 2009 12:52:52 +0100
Subject: [PATCH] fix for repeated normalizer calls against file attributes in multipart posts, including tests
---
.../lib/merb-core/dispatch/request_parsers.rb | 4 +++-
merb-core/spec/public/request/multipart_spec.rb | 2 ++
merb_datamapper/lib/merb_datamapper.rb | 4 ++--
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/merb-core/lib/merb-core/dispatch/request_parsers.rb b/merb-core/lib/merb-core/dispatch/request_parsers.rb
index 071eb33..0963c17 100644
--- a/merb-core/lib/merb-core/dispatch/request_parsers.rb
+++ b/merb-core/lib/merb-core/dispatch/request_parsers.rb
@@ -55,6 +55,7 @@ module Merb
boundary_size = boundary.size + EOL.size
bufsize = 16384
content_length -= boundary_size
+ key_memo = []
# status is boundary delimiter line
status = input.read(boundary_size)
return {} if status == nil || status.empty?
@@ -126,7 +127,8 @@ module Merb
else
data = body
end
- paramhsh = normalize_params(paramhsh,name,data)
+ paramhsh = normalize_params(paramhsh,name,data) unless key_memo.include?(name)
+ key_memo << name
break if buf.empty? || content_length == -1
}
paramhsh
diff --git a/merb-core/spec/public/request/multipart_spec.rb b/merb-core/spec/public/request/multipart_spec.rb
index f15e71d..f5c29b4 100644
--- a/merb-core/spec/public/request/multipart_spec.rb
+++ b/merb-core/spec/public/request/multipart_spec.rb
@@ -13,6 +13,7 @@ describe Merb::Request do
request.params[:file].should_not be_nil
request.params[:file][:tempfile].class.should == Tempfile
request.params[:file][:content_type].should == 'text/plain'
+ request.params[:file][:size].should == file.read.length
end
it "should accept env['rack.input'] as IO object (instead of StringIO)" do
@@ -33,6 +34,7 @@ describe Merb::Request do
request.params[:file].should_not be_nil
request.params[:file][:tempfile].class.should == Tempfile
request.params[:file][:content_type].should == 'text/plain'
+ request.params[:file][:size].should == file.read.length
end
it "should handle GET with a content_type but an empty body (happens in some browsers such as safari after redirect)" do
--
1.5.4.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment