Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 11 additions & 1 deletion sentry-ruby/lib/sentry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,17 @@ def event_from_log(message, level:, **options)

return unless body

LogEvent.new(level: level, body: body, attributes: attributes, origin: origin)
sanitized_attributes = attributes.transform_values do |value|
if value.is_a?(String)
return unless (sanitized_string = Utils::EncodingHelper.safe_utf_8_string(value))

sanitized_string
else
value
end
end

LogEvent.new(level: level, body: body, attributes: sanitized_attributes, origin: origin)
end

# Initializes an Event object with the given Transaction object.
Expand Down
7 changes: 7 additions & 0 deletions sentry-ruby/spec/sentry/structured_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@

expect(sentry_logs).to be_empty
end

it "doesn't choke on malformed UTF-8 in attributes" do
malformed_user_agent = "Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp\xA1\xB1)".dup.force_encoding("UTF-8")
Sentry.logger.public_send(level, "Valid message", user_agent: malformed_user_agent)

expect(sentry_logs).to be_empty
end
end
end

Expand Down
Loading