diff options
author | Dan Kang <dan@dskang.com> | 2014-02-08 17:40:08 -0800 |
---|---|---|
committer | Dan Kang <dan@dskang.com> | 2014-02-08 23:22:04 -0800 |
commit | 069bc273853c90194606b1725113d77ae39e2edd (patch) | |
tree | ed9e6c7b1f52adc19db3a657f9ed69a21a82b720 /actionpack | |
parent | cbd10e27d1fa6e07d39dbb6fb42ce3420c5959db (diff) | |
download | rails-069bc273853c90194606b1725113d77ae39e2edd.tar.gz rails-069bc273853c90194606b1725113d77ae39e2edd.tar.bz2 rails-069bc273853c90194606b1725113d77ae39e2edd.zip |
Prevent [response].flatten from recursing infinitely.
Returning `self` from within the array returned by `to_ary`
caused this. Instead, we can just substitute another object.
It provides the `each` behavior required by the rack spec.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/response_test.rb | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index bc13ee00f1..2c6bcf7b7b 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -313,7 +313,7 @@ module ActionDispatch # :nodoc: header.delete CONTENT_TYPE [status, header, []] else - [status, header, self] + [status, header, Rack::BodyProxy.new(self){}] end end end diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 82d29867fe..959a3bc5cd 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -226,6 +226,15 @@ class ResponseTest < ActiveSupport::TestCase assert_equal({ 'Content-Type' => 'text/plain' }, headers) assert_equal ['Not Found'], body.each.to_a end + + test "[response].flatten does not recurse infinitely" do + Timeout.timeout(1) do # use a timeout to prevent it stalling indefinitely + status, headers, body = [@response].flatten + assert_equal @response.status, status + assert_equal @response.headers, headers + assert_equal @response.body, body.each.to_a.join + end + end end class ResponseIntegrationTest < ActionDispatch::IntegrationTest |