Permalink
Browse files

Rewind readable CGI params so others may reread them (such as CGI::Se…

…ssion when passing the session id in a multipart form). Closes #210.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4410 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 6dea52c commit 8cdf9126d3c3174cad74f8ae4a913f1940d3474a @jeremy jeremy committed Jun 2, 2006
View
@@ -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)
@@ -183,7 +183,9 @@ def original_filename
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
@@ -303,13 +303,21 @@ def test_mixed_files
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

0 comments on commit 8cdf912

Please sign in to comment.