Sha256: d86576ac0644eba278f12cc10f2716c0b2f80bc10fc72af3475ebde448690788

Contents?: true

Size: 613 Bytes

Versions: 9

Compression:

Stored size: 613 Bytes

Contents

module Raven
  class Processor::UTF8Conversion < Processor

    def process(value)
      if value.is_a? Array
        value.map { |v| process v }
      elsif value.is_a? Hash
        value.merge(value) { |_, v| process v }
      else
        clean_invalid_utf8_bytes(value)
      end
    end

    private

    def clean_invalid_utf8_bytes(obj)
      if obj.respond_to?(:to_utf8)
        obj.to_utf8
      elsif obj.respond_to?(:encoding) && obj.is_a?(String)
        obj.encode('UTF-16', :invalid => :replace, :undef => :replace, :replace => '').encode('UTF-8')
      else
        obj
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sentry-raven-0.15.2 lib/raven/processor/utf8conversion.rb
sentry-raven-0.15.1 lib/raven/processor/utf8conversion.rb
sentry-raven-0.15.0 lib/raven/processor/utf8conversion.rb
sentry-raven-0.14.0 lib/raven/processor/utf8conversion.rb
sentry-raven-0.13.3 lib/raven/processor/utf8conversion.rb
sentry-raven-0.13.2 lib/raven/processor/utf8conversion.rb
sentry-raven-0.13.1 lib/raven/processor/utf8conversion.rb
sentry-raven-0.13.0 lib/raven/processor/utf8conversion.rb
sentry-raven-0.12.3 lib/raven/processor/utf8conversion.rb