提交 33be58b2 编写于 作者: A Aaron Patterson

Merge pull request #13982 from dskang/fix-response-flatten-infinite-recursion

Fix response flatten infinite recursion
......@@ -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
......
......@@ -217,6 +217,24 @@ def test_response_body_encoding
assert_not @response.respond_to?(:method_missing)
assert @response.respond_to?(:method_missing, true)
end
test "can be destructured into status, headers and an enumerable body" do
response = ActionDispatch::Response.new(404, { 'Content-Type' => 'text/plain' }, ['Not Found'])
status, headers, body = response
assert_equal 404, status
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册