Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 069bc273853c90194606b1725113d77ae39e2edd 1 parent cbd10e2
@dskang dskang authored
View
2  actionpack/lib/action_dispatch/http/response.rb
@@ -313,7 +313,7 @@ def rack_response(status, header)
header.delete CONTENT_TYPE
[status, header, []]
else
- [status, header, self]
+ [status, header, Rack::BodyProxy.new(self){}]
end
end
end
View
9 actionpack/test/dispatch/response_test.rb
@@ -226,6 +226,15 @@ def test_response_body_encoding
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
Please sign in to comment.
Something went wrong with that request. Please try again.