4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/logtail-rack/util/encoding.rb', line 4
def self.force_utf8_encoding(data)
if data.respond_to?(:force_encoding)
encoded_data = data.dup.force_encoding('UTF-8')
encoded_data = data.dup.force_encoding("ISO-8859-1").encode("UTF-8") unless encoded_data.valid_encoding?
encoded_data = data.dup.encode('UTF-8', invalid: :replace, undef: :replace) unless encoded_data.valid_encoding?
encoded_data
elsif data.respond_to?(:transform_values)
data.transform_values { |val| Logtail::Util::Encoding.force_utf8_encoding(val) }
else
data
end
end
|