mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #36370 from ptoomey3/master
Add support for Proc based parameter filtering on arrays of values
This commit is contained in:
commit
d3327ca40e
2 changed files with 13 additions and 1 deletions
|
@ -109,7 +109,12 @@ module ActiveSupport
|
||||||
elsif value.is_a?(Hash)
|
elsif value.is_a?(Hash)
|
||||||
value = call(value, parents, original_params)
|
value = call(value, parents, original_params)
|
||||||
elsif value.is_a?(Array)
|
elsif value.is_a?(Array)
|
||||||
value = value.map { |v| v.is_a?(Hash) ? call(v, parents, original_params) : v }
|
# If we don't pop the current parent it will be duplicated as we
|
||||||
|
# process each array value.
|
||||||
|
parents.pop if deep_regexps
|
||||||
|
value = value.map { |v| value_for_key(key, v, parents, original_params) }
|
||||||
|
# Restore the parent stack after processing the array.
|
||||||
|
parents.push(key) if deep_regexps
|
||||||
elsif blocks.any?
|
elsif blocks.any?
|
||||||
key = key.dup if key.duplicable?
|
key = key.dup if key.duplicable?
|
||||||
value = value.dup if value.duplicable?
|
value = value.dup if value.duplicable?
|
||||||
|
|
|
@ -28,10 +28,17 @@ class ParameterFilterTest < ActiveSupport::TestCase
|
||||||
value.replace("world!") if original_params["barg"]["blah"] == "bar" && key == "hello"
|
value.replace("world!") if original_params["barg"]["blah"] == "bar" && key == "hello"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filter_words << lambda { |key, value|
|
||||||
|
value.upcase! if key == "array_elements"
|
||||||
|
}
|
||||||
|
|
||||||
parameter_filter = ActiveSupport::ParameterFilter.new(filter_words)
|
parameter_filter = ActiveSupport::ParameterFilter.new(filter_words)
|
||||||
before_filter["barg"] = { :bargain => "gain", "blah" => "bar", "bar" => { "bargain" => { "blah" => "foo", "hello" => "world" } } }
|
before_filter["barg"] = { :bargain => "gain", "blah" => "bar", "bar" => { "bargain" => { "blah" => "foo", "hello" => "world" } } }
|
||||||
after_filter["barg"] = { :bargain => "niag", "blah" => "[FILTERED]", "bar" => { "bargain" => { "blah" => "[FILTERED]", "hello" => "world!" } } }
|
after_filter["barg"] = { :bargain => "niag", "blah" => "[FILTERED]", "bar" => { "bargain" => { "blah" => "[FILTERED]", "hello" => "world!" } } }
|
||||||
|
|
||||||
|
before_filter["array_elements"] = %w(element1 element2)
|
||||||
|
after_filter["array_elements"] = %w(ELEMENT1 ELEMENT2)
|
||||||
|
|
||||||
assert_equal after_filter, parameter_filter.filter(before_filter)
|
assert_equal after_filter, parameter_filter.filter(before_filter)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue