Skip to content
Browse files

fix filtering of nested params

  • Loading branch information...
1 parent 0d6bf34 commit cc0a0ccada1ba00556e4cf65fe3d82140865a388 @shime shime committed Mar 13, 2012
Showing with 15 additions and 7 deletions.
  1. +7 −6 lib/exceptional/controller_exception_data.rb
  2. +8 −1 spec/exceptional/exception_data_spec.rb
View
13 lib/exceptional/controller_exception_data.rb
@@ -29,12 +29,13 @@ def extra_stuff
end
def filter_hash(keys_to_filter, hash)
+ keys_to_filter.map! {|x| x.to_s}
if keys_to_filter.is_a?(Array) && !keys_to_filter.empty?
hash.each do |key, value|
- if value.respond_to?(:to_hash)
- filter_hash(keys_to_filter, hash[key])
- elsif key_match?(key, keys_to_filter)
+ if key_match?(key, keys_to_filter)
hash[key] = "[FILTERED]"
+ elsif value.respond_to?(:to_hash)
+ filter_hash(keys_to_filter, hash[key])
end
end
end
@@ -45,13 +46,13 @@ def filter_hash(keys_to_filter, hash)
# https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/parameter_filter.rb
# https://github.com/exceptional/exceptional/issues/20
def key_match?(key, keys_to_filter)
- keys_to_filter.any? { |k|
- regexp = k.is_a?(Regexp)? k : Regexp.new(k, true)
+ keys_to_filter.any? { |k|
+ regexp = k.is_a?(Regexp)? k : Regexp.new(k, true)
key =~ regexp
}
end
- def filter_parameters(hash)
+ def filter_parameters(hash)
if @request.respond_to?(:env) && @request.env["action_dispatch.parameter_filter"]
filter_hash(@request.env["action_dispatch.parameter_filter"], hash)
elsif @controller.respond_to?(:filter_parameters)
View
9 spec/exceptional/exception_data_spec.rb
@@ -127,6 +127,13 @@ def to_json
data.to_hash['request']['parameters'].should == {'var1' => '[FILTERED]'}
end
+ it "filter nested params specified in env['action_dispatch.parameter_filter']" do
+ @request.stub!(:env).and_return({'SOME_VAR' => 'abc', 'HTTP_CONTENT_TYPE' => 'text/html', 'action_dispatch.parameter_filter' => [:var1]})
+ @request.stub!(:parameters).and_return({'var1' => {'var2' => 'abc','var3' => "abc"}})
+ data = Exceptional::ControllerExceptionData.new(@error, @controller, @request)
+ data.to_hash['request']['parameters'].should == {'var1' => '[FILTERED]'}
+ end
+
it "formats the occurred_at as iso8601" do
@request.stub!(:env).and_return({'SOME_VAR' => 'abc', 'HTTP_CONTENT_TYPE' => 'text/html', 'action_dispatch.parameter_filter' => [:var1]})
@request.stub!(:parameters).and_return({'var1' => 'abc'})
@@ -195,4 +202,4 @@ def initialize
data = Exceptional::ControllerExceptionData.new(exception)
data.uniqueness_hash.should == nil
end
-end
+end

0 comments on commit cc0a0cc

Please sign in to comment.
Something went wrong with that request. Please try again.