Skip to content

Avoid wrapping nil input #2259

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

Merged
merged 2 commits into from
Nov 9, 2024
Merged

Avoid wrapping nil input #2259

merged 2 commits into from
Nov 9, 2024

Conversation

tt
Copy link
Contributor

@tt tt commented Nov 8, 2024

Rack ships with the Rack::RewindableInput::Middleware middleware for compatibility with older apps.

However, this middleware wraps rack.input unconditionally meaning that a nil input will also be wrapped potentially leading to exceptions.

Concretely, I have an older app with a middleware that's trying to req.body&.read and req.body&.rewind which for GET and HEAD requests now cause the following error:

NoMethodError: undefined method `read' for nil
   ~/.gem/ruby/3.3.6/gems/rack-3.1.8/lib/rack/rewindable_input.rb:96:in `make_rewindable'
   ~/.gem/ruby/3.3.6/gems/rack-3.1.8/lib/rack/rewindable_input.rb:41:in `read'

This middleware should probably interrogate req.request_method.

Even so, it seems that for backwards compatibility (and to avoid the possibility of runtime errors overall), it would be great to never wrap a nil value.

Copy link
Member

@ioquatix ioquatix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks okay to me.

@ioquatix ioquatix requested a review from jeremyevans November 8, 2024 09:57
@ioquatix ioquatix merged commit 3ea31c6 into rack:main Nov 9, 2024
14 checks passed
@ioquatix
Copy link
Member

ioquatix commented Nov 9, 2024

Thanks for your contribution. I hope we can release this in Rack 3.2 sometime before the end of this year.

@tt tt deleted the avoid-wrapping-nil-input branch November 9, 2024 14:22
@tt
Copy link
Contributor Author

tt commented May 19, 2025

@ioquatix, is there a new timeline for when Rack 3.2 is expected to ship?

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.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy