Skip to content

[response].flatten causes infinite loop #419

@dchelimsky

Description

@dchelimsky
  • Rack::Response#finish is aliased with to_ary [1]
  • Rack::Response#finish returns an array including selfwhen the response code is anything other than 204, 205, 304 [2]

The result is an infinite loop if the result of app.call(env) (assigned to response in Rails' testing framework) is included in an array that is flattened. The reason is that Array#flatten invokes to_ary on each element that responds to to_ary, then does the same to the contents of the result of to_ary, and so on.

Because self is in the array returned by to_ary, it gets to_ary invoked and returns the same array, including self, which then gets to_ary invoked on it, which returns the same array, including self, and so on.

[1]

alias to_ary finish # For implicit-splat on Ruby 1.9.2

[2]
[status.to_i, header, self]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions