Skip to content

Commit

Permalink
Fix inefficient assert pattern in Rack::Lint (#2101)
Browse files Browse the repository at this point in the history
Partial backport of 1970771

Differences from original commit:
- `#assert` is not deprecated
- `include Assertion` is not removed
- The assertion in `check_status` is the 2-2-stable version since the
  SPEC [change][1] to require statuses to be integers was merged before
  this
- `#dump` was added to the `REQUEST_METHOD` assertion [after][2] the
  original commit, so it was added here as well

This fixes an issue encountered when adding `Rack::Lint` to the Rails
test suite. Rails puts a lazily evaluated class inside the request env
that has the potential to raise when converted to a string. Since this
assertion in `Rack::Lint` calls `#inspect` on `env` whether or not `env`
is a `Hash`, the lazily evaluated class would raise at that point and
prevent the rest of `Rack::Lint` from validating the conformity of the
request.

By backporting this change, `#inspect` is now only called when the
`LintError` would be raised which avoids the problem.

[1]: ba25ade
[2]: b426cc2

Co-authored-by: Benoit Daloze <eregontp@gmail.com>
  • Loading branch information
skipkayhil and eregon committed Jul 31, 2023
1 parent 1fdcf1f commit cee73b3
Showing 1 changed file with 177 additions and 188 deletions.

0 comments on commit cee73b3

Please sign in to comment.