From 0773bd657e31611990626f1732fc5122d328a05f Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Mon, 12 Mar 2018 08:32:15 +0200 Subject: [PATCH] filters/keys_filter: handle non-hash values Fixes #308 (Change in 2.8.2 makes airbrake crash on error when filtering array typed keys) We should simply return non-hash values to make recursion stop failing. --- CHANGELOG.md | 4 ++++ lib/airbrake-ruby/filters/keys_filter.rb | 2 ++ spec/filters/keys_blacklist_spec.rb | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43b642f7..40b8c2e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Airbrake Ruby Changelog ### master +* Fixed bug introduced in v2.8.2 in blacklist/whitelist filtering. All + v2.8.2 users must upgrade to the recent version + ([#309](https://github.com/airbrake/airbrake-ruby/pull/309)) + ### [v2.8.2][v2.8.2] (March 5, 2018) * Fixed bug where params inside arrays couldn't be diff --git a/lib/airbrake-ruby/filters/keys_filter.rb b/lib/airbrake-ruby/filters/keys_filter.rb index b2150ee8..6dcc8c90 100644 --- a/lib/airbrake-ruby/filters/keys_filter.rb +++ b/lib/airbrake-ruby/filters/keys_filter.rb @@ -73,6 +73,8 @@ def should_filter?(_key) private def filter_hash(hash) + return hash unless hash.is_a?(Hash) + hash.each_key do |key| if should_filter?(key.to_s) hash[key] = FILTERED diff --git a/spec/filters/keys_blacklist_spec.rb b/spec/filters/keys_blacklist_spec.rb index 028699e7..356f821d 100644 --- a/spec/filters/keys_blacklist_spec.rb +++ b/spec/filters/keys_blacklist_spec.rb @@ -65,8 +65,8 @@ 'pattern matching', ['bingo'], [ - { array: [bingo: 'bango'] }, - { array: [bingo: '[Filtered]'] } + { array: [{ bingo: 'bango' }, []] }, + { array: [{ bingo: '[Filtered]' }, []] } ] ) end