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

wrap request.path_parameters for request.paramters #19860

Closed
wants to merge 1 commit into from

Conversation

sonots
Copy link

@sonots sonots commented Apr 22, 2015

Currently, wrap_parameters does not wrap request.path_parameters.

I propose that request.parameters wraps request.path_parameters in addition to request.request_parameters so that we can get the id parameter often assigned as path parameters (like get '/books/:id').

request.request_parameters is kept as is so that it wraps only request.request_parameters.

@sonots
Copy link
Author

sonots commented Apr 22, 2015

I think the specification of this PR is more natural than the old implementation, but please let me know if there are any reasons that the specification must be kept as the old implementation.

@rafaelfranca
Copy link
Member

cc @jeremy

@sgrif
Copy link
Contributor

sgrif commented Oct 20, 2015

r? @jeremy

@rails-bot rails-bot assigned jeremy and unassigned sgrif Oct 20, 2015
@sikachu
Copy link
Member

sikachu commented Dec 13, 2015

Ping @jeremy ?

@sikachu sikachu added this to the 5.0.0 milestone Dec 13, 2015
@jeremy
Copy link
Member

jeremy commented Dec 14, 2015

+1 in principle. Would merging these params break any apps? Why / why not?

@sikachu
Copy link
Member

sikachu commented Dec 14, 2015

One thing I could see right away is that it's possible that parent's id (when you have a route such as /posts/1/comments) would now get included into the wrapped params. However, I think that's a desired side effect, and you probably are going to perform a require/permit to filter out the parameters anyway.

With that said, @sonots I think we should add a test case for nested id (/users/:user_id/comments/:comment_id, for example), just so we can prevent further regression.

@sonots sonots force-pushed the wrap_path_parameters branch 2 times, most recently from c5727dd to 9fbbddd Compare December 16, 2015 05:02
@sonots
Copy link
Author

sonots commented Dec 16, 2015

@jeremy @sikachu added test cases for nested id

@@ -50,7 +64,23 @@ def test_filtered_parameters
with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, params: { 'username' => 'sikachu' }
assert_equal @request.filtered_parameters, { 'controller' => 'params_wrapper_test/users', 'action' => 'parse', 'username' => 'sikachu', 'user' => { 'username' => 'sikachu' } }
assert_equal({ 'controller' => 'params_wrapper_test/users', 'action' => 'parse', 'username' => 'sikachu', 'user' => { 'username' => 'sikachu' } }, @request.filtered_parameters)
Copy link
Author

Choose a reason for hiding this comment

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

changed the order because assert_equal expected, actual

@rafaelfranca rafaelfranca removed this from the 5.0.0 [temp] milestone Apr 5, 2016
else
wrapped_hash = _wrap_parameters request.request_parameters
wrapped_hash = _wrap_parameters request.parameters
wrapped_request_hash = _wrap_parameters request.request_parameters
end

wrapped_keys = request.request_parameters.keys
wrapped_filtered_hash = _wrap_parameters request.filtered_parameters.slice(*wrapped_keys)
Copy link
Member

Choose a reason for hiding this comment

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

I think the slice stuff here is now unnecessary and incorrect - previously we only wrapped request parameters, so we had to filter out query and path parameters here. Now we're wrapping all parameters, so this can just be:

wrapped_filtered_hash = _wrap_parameters request.filtered_parameters

Copy link
Author

Choose a reason for hiding this comment

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

thanks, fixed

@rails-bot
Copy link

rails-bot bot commented Dec 18, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Dec 18, 2019
@rails-bot rails-bot bot closed this Dec 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants