Skip to content

Commit

Permalink
If a custom object responds to id method, show the id value, instea…
Browse files Browse the repository at this point in the history
…d of showing "[OBJECT]"
  • Loading branch information
manojmj92 committed Feb 8, 2019
1 parent bf0383a commit 64f97b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/bugsnag/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ def traverse_object(obj, seen, scope)
str = obj.to_s rescue RAISED
# avoid leaking potentially sensitive data from objects' #inspect output
if str =~ /#<.*>/
OBJECT
# Use id of the object if available
if obj.respond_to?(:id)
obj.id
else
OBJECT
end
else
clean_string(str)
end
Expand Down
10 changes: 10 additions & 0 deletions spec/cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ class Macaron; end
expect(subject.clean_object(a)).to eq('[OBJECT]')
end

it "cleans custom objects to show the id of the object if object responds to id method" do
class Macaron
def id
10
end
end
a = Macaron.new
expect(subject.clean_object(a)).to eq(a.id)
end

it "cleans up binary strings properly" do
if RUBY_VERSION > "1.9"
obj = "Andr\xc7\xff"
Expand Down

0 comments on commit 64f97b4

Please sign in to comment.