From 1d7fa920bf3bb4496f4782de6128029f3ecd4a62 Mon Sep 17 00:00:00 2001 From: Patrick Toomey Date: Fri, 31 May 2019 07:49:28 -0600 Subject: 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. --- activesupport/lib/active_support/parameter_filter.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') 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? -- cgit v1.2.3 From 91f973a803aa1310ffe07bd519671e897fa7e918 Mon Sep 17 00:00:00 2001 From: Patrick Toomey Date: Fri, 31 May 2019 08:17:14 -0600 Subject: Fix typo --- activesupport/lib/active_support/parameter_filter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/parameter_filter.rb b/activesupport/lib/active_support/parameter_filter.rb index d58941c4e1..7850fb9467 100644 --- a/activesupport/lib/active_support/parameter_filter.rb +++ b/activesupport/lib/active_support/parameter_filter.rb @@ -110,7 +110,7 @@ module ActiveSupport elsif value.is_a?(Hash) value = call(value, parents, original_params) elsif value.is_a?(Array) - # If we don't pop of the current parent it will be duplicated as we + # 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 do |v| -- cgit v1.2.3 From 29164f348e6aacf9e5f8cff6aeaa43fedcf98645 Mon Sep 17 00:00:00 2001 From: Patrick Toomey Date: Fri, 31 May 2019 08:19:20 -0600 Subject: Use style consistent with surrounding code --- activesupport/lib/active_support/parameter_filter.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/parameter_filter.rb b/activesupport/lib/active_support/parameter_filter.rb index 7850fb9467..7114cc8efb 100644 --- a/activesupport/lib/active_support/parameter_filter.rb +++ b/activesupport/lib/active_support/parameter_filter.rb @@ -113,9 +113,7 @@ module ActiveSupport # 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 do |v| - value_for_key(key, v, parents, original_params) - end + 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? -- cgit v1.2.3