Skip to content

Commit

Permalink
Rewind readable CGI params so others may reread them (such as CGI::Se…
Browse files Browse the repository at this point in the history
…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
jeremy committed Jun 2, 2006
1 parent 6dea52c commit 8cdf912
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions actionpack/CHANGELOG
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN* *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::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) * Added Mime::Type.register(string, symbol, synonyms = []) for adding new custom mime types [DHH]. Example: Mime::Type.register("image/gif", :gif)
Expand Down
4 changes: 3 additions & 1 deletion actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ def original_filename


elsif value.respond_to?(:read) elsif value.respond_to?(:read)
# Value as part of a multipart request # Value as part of a multipart request
value.read result = value.read
value.rewind
result
elsif value.class == Array elsif value.class == Array
value.collect { |v| CGIMethods.get_typed_value(v) } value.collect { |v| CGIMethods.get_typed_value(v) }
else else
Expand Down
10 changes: 9 additions & 1 deletion actionpack/test/controller/cgi_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -303,13 +303,21 @@ def test_mixed_files
assert_equal 19756, params['files'].size assert_equal 19756, params['files'].size
end 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 private
def process(name) def process(name)
old_stdin = $stdin old_stdin = $stdin
File.open(File.join(FIXTURE_PATH, name), 'rb') do |file| File.open(File.join(FIXTURE_PATH, name), 'rb') do |file|
ENV['CONTENT_LENGTH'] = file.stat.size.to_s ENV['CONTENT_LENGTH'] = file.stat.size.to_s
$stdin = file $stdin = file
CGIMethods.parse_request_parameters CGI.new.params @cgi = CGI.new
CGIMethods.parse_request_parameters @cgi.params
end end
ensure ensure
$stdin = old_stdin $stdin = old_stdin
Expand Down

0 comments on commit 8cdf912

Please sign in to comment.