aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http
diff options
context:
space:
mode:
authorYoshiyuki Kinjo <yskkin@gmail.com>2018-09-21 13:49:59 +0900
committerYoshiyuki Kinjo <yskkin@gmail.com>2018-10-08 08:05:40 +0900
commit7f80be29a2655757985b8f70855940f4dc5445cf (patch)
tree0aca90c417c378b18c9cfb922576b84034a4c48a /actionpack/lib/action_dispatch/http
parent0b4cfa2ba3e978386240e0e56a409616cc32fd02 (diff)
downloadrails-7f80be29a2655757985b8f70855940f4dc5445cf.tar.gz
rails-7f80be29a2655757985b8f70855940f4dc5445cf.tar.bz2
rails-7f80be29a2655757985b8f70855940f4dc5445cf.zip
Deprecate ActionDispatch::Http::ParameterFilter in favor of ActiveSupport::ParameterFilter
Diffstat (limited to 'actionpack/lib/action_dispatch/http')
-rw-r--r--actionpack/lib/action_dispatch/http/filter_parameters.rb8
-rw-r--r--actionpack/lib/action_dispatch/http/parameter_filter.rb85
2 files changed, 9 insertions, 84 deletions
diff --git a/actionpack/lib/action_dispatch/http/filter_parameters.rb b/actionpack/lib/action_dispatch/http/filter_parameters.rb
index ec012ad02d..9f8f178402 100644
--- a/actionpack/lib/action_dispatch/http/filter_parameters.rb
+++ b/actionpack/lib/action_dispatch/http/filter_parameters.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require "action_dispatch/http/parameter_filter"
+require "active_support/parameter_filter"
module ActionDispatch
module Http
@@ -28,8 +28,8 @@ module ActionDispatch
# => reverses the value to all keys matching /secret/i
module FilterParameters
ENV_MATCH = [/RAW_POST_DATA/, "rack.request.form_vars"] # :nodoc:
- NULL_PARAM_FILTER = ParameterFilter.new # :nodoc:
- NULL_ENV_FILTER = ParameterFilter.new ENV_MATCH # :nodoc:
+ NULL_PARAM_FILTER = ActiveSupport::ParameterFilter.new # :nodoc:
+ NULL_ENV_FILTER = ActiveSupport::ParameterFilter.new ENV_MATCH # :nodoc:
def initialize
super
@@ -69,7 +69,7 @@ module ActionDispatch
end
def parameter_filter_for(filters) # :doc:
- ParameterFilter.new(filters)
+ ActiveSupport::ParameterFilter.new(filters)
end
KV_RE = "[^&;=]+"
diff --git a/actionpack/lib/action_dispatch/http/parameter_filter.rb b/actionpack/lib/action_dispatch/http/parameter_filter.rb
index 6689092859..ddeb3d81e2 100644
--- a/actionpack/lib/action_dispatch/http/parameter_filter.rb
+++ b/actionpack/lib/action_dispatch/http/parameter_filter.rb
@@ -1,87 +1,12 @@
# frozen_string_literal: true
-require "active_support/core_ext/object/duplicable"
-require "active_support/core_ext/array/extract"
+require "active_support/deprecation/constant_accessor"
+require "active_support/parameter_filter"
module ActionDispatch
module Http
- class ParameterFilter
- FILTERED = "[FILTERED]" # :nodoc:
-
- def initialize(filters = [])
- @filters = filters
- end
-
- def filter(params)
- compiled_filter.call(params)
- end
-
- private
-
- def compiled_filter
- @compiled_filter ||= CompiledFilter.compile(@filters)
- end
-
- class CompiledFilter # :nodoc:
- def self.compile(filters)
- return lambda { |params| params.dup } if filters.empty?
-
- strings, regexps, blocks = [], [], []
-
- filters.each do |item|
- case item
- when Proc
- blocks << item
- when Regexp
- regexps << item
- else
- strings << Regexp.escape(item.to_s)
- end
- end
-
- deep_regexps = regexps.extract! { |r| r.to_s.include?("\\.") }
- deep_strings = strings.extract! { |s| s.include?("\\.") }
-
- regexps << Regexp.new(strings.join("|"), true) unless strings.empty?
- deep_regexps << Regexp.new(deep_strings.join("|"), true) unless deep_strings.empty?
-
- new regexps, deep_regexps, blocks
- end
-
- attr_reader :regexps, :deep_regexps, :blocks
-
- def initialize(regexps, deep_regexps, blocks)
- @regexps = regexps
- @deep_regexps = deep_regexps.any? ? deep_regexps : nil
- @blocks = blocks
- end
-
- def call(params, parents = [], original_params = params)
- filtered_params = params.class.new
-
- params.each do |key, value|
- parents.push(key) if deep_regexps
- if regexps.any? { |r| key =~ r }
- value = FILTERED
- elsif deep_regexps && (joined = parents.join(".")) && deep_regexps.any? { |r| joined =~ r }
- value = FILTERED
- 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 }
- elsif blocks.any?
- key = key.dup if key.duplicable?
- value = value.dup if value.duplicable?
- blocks.each { |b| b.arity == 2 ? b.call(key, value) : b.call(key, value, original_params) }
- end
- parents.pop if deep_regexps
-
- filtered_params[key] = value
- end
-
- filtered_params
- end
- end
- end
+ include ActiveSupport::Deprecation::DeprecatedConstantAccessor
+ deprecate_constant "ParameterFilter", "ActiveSupport::ParameterFilter",
+ message: "ActionDispatch::Http::ParameterFilter is deprecated and will be removed from Rails 6.1. Use ActiveSupport::ParameterFilter instead."
end
end