From 24eb5489bb99846c86a4910e8d04278a8e97a044 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Thu, 11 May 2017 19:05:27 +0300 Subject: [PATCH] filters/keys_filter: handle hash keys that are not symbols/strings Fixes https://github.com/airbrake/airbrake/issues/739 (Error Handler Threw An Error - Sidekiq) --- lib/airbrake-ruby/filters/keys_filter.rb | 2 +- spec/filters/keys_blacklist_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 spec/filters/keys_blacklist_spec.rb diff --git a/lib/airbrake-ruby/filters/keys_filter.rb b/lib/airbrake-ruby/filters/keys_filter.rb index 1fb777fd..c1e9bfdf 100644 --- a/lib/airbrake-ruby/filters/keys_filter.rb +++ b/lib/airbrake-ruby/filters/keys_filter.rb @@ -70,7 +70,7 @@ def should_filter?(_key) def filter_hash(hash) hash.each_key do |key| - if should_filter?(key) + if should_filter?(key.to_s) hash[key] = FILTERED elsif hash[key].is_a?(Hash) filter_hash(hash[key]) diff --git a/spec/filters/keys_blacklist_spec.rb b/spec/filters/keys_blacklist_spec.rb new file mode 100644 index 00000000..e82ed86f --- /dev/null +++ b/spec/filters/keys_blacklist_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +RSpec.describe Airbrake::Filters::KeysBlacklist do + subject do + described_class.new(Logger.new('/dev/null'), patterns) + end + + describe "#call" do + let(:notice) do + Airbrake::Notice.new(Airbrake::Config.new, AirbrakeTestError.new) + end + + context "when a pattern is a regexp and when a key is a hash" do + let(:patterns) { [/bango/] } + + it "doesn't fail" do + notice[:params] = { bingo: { {} => 'unfiltered' } } + expect { subject.call(notice) }.not_to raise_error + end + end + end +end