Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a custom object responds to id method, show the id and class value, instead of showing "[OBJECT]" in error reports #531

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/bugsnag/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Cleaner
RECURSION = '[RECURSION]'.freeze
OBJECT = '[OBJECT]'.freeze
RAISED = '[RAISED]'.freeze
OBJECT_WITH_ID_AND_CLASS = '[OBJECT]: [Class]: %{class_name} [ID]: %{id}'.freeze

def initialize(filters)
@filters = Array(filters)
Expand Down Expand Up @@ -47,7 +48,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)
OBJECT_WITH_ID_AND_CLASS % { class_name: obj.class, 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("[OBJECT]: [Class]: #{a.class.name} [ID]: #{a.id}")
end

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