Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 8cdf9126d3c3174cad74f8ae4a913f1940d3474a 1 parent 6dea52c
@jeremy jeremy authored
View
2  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)
View
4 actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
@@ -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
View
10 actionpack/test/controller/cgi_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.