aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorPatrick Toomey <ptoomey3@biasedcoin.com>2019-05-31 07:49:28 -0600
committerPatrick Toomey <ptoomey3@biasedcoin.com>2019-05-31 07:49:28 -0600
commit1d7fa920bf3bb4496f4782de6128029f3ecd4a62 (patch)
treee29b754b8ad5031dee812580fce7cd1ba1697083 /activesupport/lib
parent06992d50522c5dd2e7fa26bc257cc416b7f47cc8 (diff)
downloadrails-1d7fa920bf3bb4496f4782de6128029f3ecd4a62.tar.gz
rails-1d7fa920bf3bb4496f4782de6128029f3ecd4a62.tar.bz2
rails-1d7fa920bf3bb4496f4782de6128029f3ecd4a62.zip
Recursively process arrays consistently
Based on the way parameters are currently processed, a parameter value of type Hash is recursively processed. For a value of type Array however, the current behavior is to simply return the original array, with no filtering. It is not clear what the expected behavior should be. But, doing nothing seems incorrect, since it bypasses custom Proc based parameter filtering all together for arrays of values. This change processes values of type Array consistently. We map over the values and recursively call value_for_key on them. This still works with values of type Hash, since value_for_key already knows how to process Hash values.
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/parameter_filter.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/parameter_filter.rb b/activesupport/lib/active_support/parameter_filter.rb
index 1389d82523..d58941c4e1 100644
--- a/activesupport/lib/active_support/parameter_filter.rb
+++ b/activesupport/lib/active_support/parameter_filter.rb
@@ -110,7 +110,14 @@ module ActiveSupport
elsif value.is_a?(Hash)
value = call(value, parents, original_params)
elsif value.is_a?(Array)
- value = value.map { |v| v.is_a?(Hash) ? call(v, parents, original_params) : v }
+ # If we don't pop of the current parent it will be duplicated as we
+ # process each array value.
+ parents.pop if deep_regexps
+ value = value.map do |v|
+ value_for_key(key, v, parents, original_params)
+ end
+ # Restore the parent stack after processing the array.
+ parents.push(key) if deep_regexps
elsif blocks.any?
key = key.dup if key.duplicable?
value = value.dup if value.duplicable?