lib/scrub_params/parameters.rb in scrub_params-0.0.3 vs lib/scrub_params/parameters.rb in scrub_params-0.0.4

- old
+ new

@@ -4,38 +4,39 @@ included do attr_accessor :scrubbed_keys end - def scrub! + def scrub self.scrubbed_keys = [] + hash = {} each_pair do |k, v| - self[k] = scrub_value(k, v) + hash[k] = scrub_value(k, v) end if scrubbed_keys.any? - ActiveSupport::Notifications.instrument("scrubbed_parameters.action_controller", keys: scrubbed_keys) + ActiveSupport::Notifications.instrument("scrubbed_parameters.action_controller", keys: scrubbed_keys.uniq) end - self + hash end protected def scrub_value(key, value) case value - when Hash - h = {} - value.each do |k, v| - h[k] = scrub_value(k, v) - end - h - when Array - value.map{|v| scrub_value(key, v) } when String scrubbed_value = ActionController::Base.helpers.strip_tags(value) if scrubbed_value != value - self.scrubbed_keys << key unless scrubbed_keys.include?(key) + self.scrubbed_keys << key end scrubbed_value + when Hash + hash = {} + value.each do |k, v| + hash[k] = scrub_value(k, v) + end + hash + when Array + value.map{|v| scrub_value(key, v) } else value end end