Skip to content

Commit

Permalink
Merge pull request #54 from airbrake/filtering-fix
Browse files Browse the repository at this point in the history
filters: compare non-regexp keys exactly
  • Loading branch information
kyrylo committed Mar 3, 2016
2 parents f34a388 + fa9023e commit 964f72e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Airbrake Ruby Changelog

### master

* Fixed bug when similar keys would be filtered out using non-regexp values for
`Airbrake.blacklist/whitelist_keys`
([#54](https://github.com/airbrake/airbrake-ruby/pull/54))

### [v1.1.0][v1.1.0] (February 25, 2016)

* Fixed bug in Ruby < 2.2, when trying to encode components while filtering
Expand Down
8 changes: 7 additions & 1 deletion lib/airbrake-ruby/filters/keys_blacklist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ class KeysBlacklist
# @return [Boolean] true if the key matches at least one pattern, false
# otherwise
def should_filter?(key)
@patterns.any? { |pattern| key.to_s.match(pattern) }
@patterns.any? do |pattern|
if pattern.is_a?(Regexp)
key.match(pattern)
else
key.to_s == pattern.to_s
end
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/airbrake-ruby/filters/keys_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module KeysFilter
#
# @param [Array<String,Regexp,Symbol>] patterns
def initialize(*patterns)
@patterns = patterns.map(&:to_s)
@patterns = patterns
end

##
Expand Down
8 changes: 7 additions & 1 deletion lib/airbrake-ruby/filters/keys_whitelist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ class KeysWhitelist
# @return [Boolean] true if the key doesn't match any pattern, false
# otherwise.
def should_filter?(key)
@patterns.none? { |pattern| key.to_s.match(pattern) }
@patterns.none? do |pattern|
if pattern.is_a?(Regexp)
key.match(pattern)
else
key.to_s == pattern.to_s
end
end
end
end
end
Expand Down
19 changes: 13 additions & 6 deletions spec/notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,11 @@ def to_json(*)
it "accepts strings" do
@airbrake.blacklist_keys('bingo')

@airbrake.notify_sync(ex, bingo: 'bango')
@airbrake.notify_sync(ex, bingo: 'bango', bbingoo: 'bbangoo')

expect(
a_request(:post, endpoint).
with(body: /"params":{"bingo":"\[Filtered\]"}/)
with(body: /"params":{"bingo":"\[Filtered\]","bbingoo":"bbangoo"}/)
).to have_been_made.once
end
end
Expand Down Expand Up @@ -586,13 +586,20 @@ def to_json(*)
it "accepts strings" do
@airbrake.whitelist_keys('bash')

@airbrake.notify_sync(ex, bingo: 'bango', bongo: 'bish', bash: 'bosh')

body = /"params":{"bingo":"\[Filtered\]","bongo":"\[Filtered\]","bash":"bosh"}/
@airbrake.notify_sync(
ex,
bingo: 'bango',
bongo: 'bish',
bash: 'bosh',
bbashh: 'bboshh'
)

expect(
a_request(:post, endpoint).
with(body: body)
with(
body: /"params":{"bingo":"\[Filtered\]","bongo":"\[Filtered\]",
"bash":"bosh","bbashh":"\[Filtered\]"}/x
)
).to have_been_made.once
end
end
Expand Down

0 comments on commit 964f72e

Please sign in to comment.