1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #13863 from joshjordan/jsj-dont-throw-out-get-params

Do not discard query parameters on requests that use wrap_parameters

Conflicts:
	actionpack/CHANGELOG.md
This commit is contained in:
Rafael Mendonça França 2014-02-01 15:53:27 -02:00
commit e9be1c1e80
3 changed files with 36 additions and 4 deletions

View file

@ -1,3 +1,8 @@
* Do not discard query parameters that form a hash with the same root key as
the `wrapper_key` for a request using `wrap_parameters`.
*Josh Jordan*
* Add `:serializer` option for `config.session_store :cookie_store`. This
changes default serializer when using `:cookie_store`.

View file

@ -231,7 +231,12 @@ module ActionController
# by the metal call stack.
def process_action(*args)
if _wrapper_enabled?
wrapped_hash = _wrap_parameters request.request_parameters
if request.parameters[_wrapper_key].present?
wrapped_hash = _extract_parameters(request.parameters)
else
wrapped_hash = _wrap_parameters request.request_parameters
end
wrapped_keys = request.request_parameters.keys
wrapped_filtered_hash = _wrap_parameters request.filtered_parameters.slice(*wrapped_keys)
@ -259,14 +264,16 @@ module ActionController
# Returns the list of parameters which will be selected for wrapped.
def _wrap_parameters(parameters)
value = if include_only = _wrapper_options.include
{ _wrapper_key => _extract_parameters(parameters) }
end
def _extract_parameters(parameters)
if include_only = _wrapper_options.include
parameters.slice(*include_only)
else
exclude = _wrapper_options.exclude || []
parameters.except(*(exclude + EXCLUDE_PARAMETERS))
end
{ _wrapper_key => value }
end
# Checks if we should perform parameters wrapping.

View file

@ -188,6 +188,26 @@ class ParamsWrapperTest < ActionController::TestCase
assert_parameters({ 'username' => 'sikachu', 'title' => 'Developer', 'user' => { 'username' => 'sikachu', 'title' => 'Developer' }})
end
end
def test_preserves_query_string_params
with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
get :parse, { 'user' => { 'username' => 'nixon' } }
assert_parameters(
{'user' => { 'username' => 'nixon' } }
)
end
end
def test_empty_parameter_set
with_default_wrapper_options do
@request.env['CONTENT_TYPE'] = 'application/json'
post :parse, {}
assert_parameters(
{'user' => { } }
)
end
end
end
class NamespacedParamsWrapperTest < ActionController::TestCase