-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Only merge params option if params is a Hash in url_for helper #42020
Conversation
Don't we need a test? |
@benoittgt I added a test in the pull request @marivaldo just referenced, can pluck it from there. It actually tests the issue through a controller test case, which is how I first encountered the bug, but it might be better to test more directly. |
@benoittgt I made a test for when params are not a hash. which made me realise that if you inspect the options that |
nudge |
@@ -822,8 +822,10 @@ def url_for(options, route_name = nil, url_strategy = UNKNOWN, method_name = nil | |||
path = route_with_params.path(method_name) | |||
params = route_with_params.params | |||
|
|||
if options.key? :params | |||
if options[:params].is_a?(Hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this broke our app quite extensively as it's not rare for options[:params]
to be an ActionController::Parameters
.
I'll fix it in #42603, feel free to chime in.
Ref: rails#42020 It's not uncommon to want to forward request parameters, as such the `:params` paramter of `url_for` often receive an AC::Parameters instance.
This PR Fixes the problem described in this original issue that was fixed here and reverted here
The fix was reverted because the keyword params is special and is used to make possible to pass parameters that are reserved.
So this fix suggests to only merge params when it is a
Hash
.The example in the revert commit from @rafaelfranca suggests that params, when used, takes the form of a Hash.
closes #42028
closes #42052