Sha256: 0e196dbe1f20f2ceb16ae51ec7aa07dd2dae96a3a1c126561dfed880e20c3ca0

Contents?: true

Size: 617 Bytes

Versions: 2

Compression:

Stored size: 617 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) { |k, 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

2 entries across 2 versions & 1 rubygems

Version Path
sentry-raven-0.12.2 lib/raven/processor/utf8conversion.rb
sentry-raven-0.12.1 lib/raven/processor/utf8conversion.rb