Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inefficient assert pattern in Rack::Lint [2-2-stable] #2101

Merged
merged 1 commit into from Jul 31, 2023

Conversation

skipkayhil
Copy link
Contributor

@skipkayhil skipkayhil commented Jul 30, 2023

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 to require statuses to be integers was merged before this
  • #dump was added to the REQUEST_METHOD assertion after 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.


I started with the smallest change needed to fix the problem in the Rails test suite, but I'm happy to add more based on feedback

@ioquatix
Copy link
Member

@skipkayhil I've talked with everyone and we agree that if you want to implement this for all of Rack::Lint (backport or rework), we'd happily accept it. Otherwise, if it's just this one causing problems, that's also okay.

LMK.

@skipkayhil
Copy link
Contributor Author

Awesome! I'll go ahead and do them all

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>
@ioquatix ioquatix merged commit cee73b3 into rack:2-2-stable Jul 31, 2023
8 checks passed
@skipkayhil skipkayhil deleted the hm-backport-1724 branch July 31, 2023 02:41
@ioquatix ioquatix added this to the v2.2.8 milestone Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants