fix: replace CGI.parse with Rack::Utils.parse_query for Ruby 4.0 compatibility#2058
Open
bvogel wants to merge 2 commits intoShopify:mainfrom
Open
fix: replace CGI.parse with Rack::Utils.parse_query for Ruby 4.0 compatibility#2058bvogel wants to merge 2 commits intoShopify:mainfrom
bvogel wants to merge 2 commits intoShopify:mainfrom
Conversation
…atibility CGI.parse was removed from Ruby's standard library in Ruby 4.0, causing a NoMethodError in LoginProtection#return_address_with_params on every OAuth callback, breaking authentication entirely on Ruby 4.0. Replace with Rack::Utils.parse_query, which is already available as a transitive dependency of Rails. It returns a plain hash with string values directly, so the .transform_values unwrapping step is no longer needed either. Fixes Shopify#2057
Author
|
back-porting this to the v22 branch would help a lot, as we still need to migrate to v23 for our project |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2057
CGI.parsewas removed from Ruby's standard library in Ruby 4.0, causing aNoMethodErrorinLoginProtection#return_address_with_paramson every OAuth callback. This breaks authentication entirely on Ruby 4.0 — the callback 500s before the session can be stored.Change
Replace
CGI.parsewithRack::Utils.parse_query, which is already available as a transitive dependency of Rails (no new dependency introduced).Rack::Utils.parse_queryreturns a plain hash with string values directly, so the.transform_valuesunwrapping step (which existed to flattenCGI.parse's array-of-strings format) is no longer needed — the result is also slightly simpler.Behaviour difference
For Shopify URL params, none. The only theoretical difference is duplicate keys:
CGI.parsewould collect them into an array, whileRack::Utils.parse_querykeeps the last value. Shopify-generated query strings never have duplicate parameter names.Testing
Existing test coverage for
return_address_with_paramsshould confirm correctness. Manually verified on Ruby 4.0.1 + Rails 8.1.