aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/lib/action_controller/cgi_ext/cgi_methods.rb4
-rwxr-xr-xactionpack/test/controller/cgi_test.rb10
3 files changed, 14 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 0f034510ac..98a65b1883 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Rewind readable CGI params so others may reread them (such as CGI::Session when passing the session id in a multipart form). #210 [mklame@atxeu.com, matthew@walker.wattle.id.au]
+
* Added Mime::TEXT (text/plain) and Mime::ICS (text/calendar) as new default types [DHH]
* Added Mime::Type.register(string, symbol, synonyms = []) for adding new custom mime types [DHH]. Example: Mime::Type.register("image/gif", :gif)
diff --git a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
index 187516d576..be5923e8de 100755
--- a/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
+++ b/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
@@ -183,7 +183,9 @@ class CGIMethods #:nodoc:
elsif value.respond_to?(:read)
# Value as part of a multipart request
- value.read
+ result = value.read
+ value.rewind
+ result
elsif value.class == Array
value.collect { |v| CGIMethods.get_typed_value(v) }
else
diff --git a/actionpack/test/controller/cgi_test.rb b/actionpack/test/controller/cgi_test.rb
index 0415a1384c..f0af5b4ed3 100755
--- a/actionpack/test/controller/cgi_test.rb
+++ b/actionpack/test/controller/cgi_test.rb
@@ -303,13 +303,21 @@ class MultipartCGITest < Test::Unit::TestCase
assert_equal 19756, params['files'].size
end
+ # Rewind readable cgi params so others may reread them (such as CGI::Session
+ # when passing the session id in a multipart form).
+ def test_multipart_param_rewound
+ params = process('text_file')
+ assert_equal 'bar', @cgi.params['foo'][0].read
+ end
+
private
def process(name)
old_stdin = $stdin
File.open(File.join(FIXTURE_PATH, name), 'rb') do |file|
ENV['CONTENT_LENGTH'] = file.stat.size.to_s
$stdin = file
- CGIMethods.parse_request_parameters CGI.new.params
+ @cgi = CGI.new
+ CGIMethods.parse_request_parameters @cgi.params
end
ensure
$stdin = old_stdin