Class: Sentry::Scrubbers::EmailSanitizer

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/scrubbers/email_sanitizer.rb

Constant Summary collapse

EMAIL_REGEX =
/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/i

Instance Method Summary collapse

Instance Method Details

#contains_email?(str) ⇒ Boolean (private)

Returns:

  • (Boolean)


42
43
44
# File 'lib/sentry/scrubbers/email_sanitizer.rb', line 42

def contains_email?(str)
  EMAIL_REGEX.match(str)
end

#process(value) ⇒ Object

largely duplicated code from from the raven-ruby lib as recommended in their doc github.com/getsentry/raven-ruby/blob/master/lib/raven/processor/utf8conversion.rb#L9



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sentry/scrubbers/email_sanitizer.rb', line 13

def process(value)
  case value
  when Hash
    value.frozen? ? value.merge(value) { |_, v| process v } : value.merge!(value) { |_, v| process v }
  when Array
    value.frozen? ? value.map { |v| process v } : value.map! { |v| process v }
  when Exception
    sanitized_exception(value)
  when String
    sanitized_string(value)
  else
    value
  end
end

#sanitized_exception(exception) ⇒ Object (private)



34
35
36
37
38
39
40
# File 'lib/sentry/scrubbers/email_sanitizer.rb', line 34

def sanitized_exception(exception)
  return exception unless contains_email?(exception.message)

  clean_exc = exception.class.new(sanitized_string(exception.message))
  clean_exc.set_backtrace(exception.backtrace)
  clean_exc
end

#sanitized_string(str) ⇒ Object (private)



30
31
32
# File 'lib/sentry/scrubbers/email_sanitizer.rb', line 30

def sanitized_string(str)
  str.gsub(EMAIL_REGEX, '[FILTERED EMAIL]')
end