lib/rollbar/encoding/encoder.rb in rollbar-2.23.1 vs lib/rollbar/encoding/encoder.rb in rollbar-2.23.2
- old
+ new
@@ -1,11 +1,10 @@
module Rollbar
module Encoding
class Encoder
ALL_ENCODINGS = [::Encoding::UTF_8, ::Encoding::ISO_8859_1, ::Encoding::ASCII_8BIT, ::Encoding::US_ASCII].freeze
ASCII_ENCODINGS = [::Encoding::US_ASCII, ::Encoding::ASCII_8BIT, ::Encoding::ISO_8859_1].freeze
- ENCODING_OPTIONS = { :invalid => :replace, :undef => :replace, :replace => '' }.freeze
UTF8 = 'UTF-8'.freeze
BINARY = 'binary'.freeze
attr_accessor :object
@@ -19,11 +18,17 @@
# This will be most of cases so avoid force anything for them
encoded_value = if encoding == ::Encoding::UTF_8 && value.valid_encoding?
value
else
- force_encoding(value).encode(*encoding_args(value))
+ force_encoding(value).encode(
+ *encoding_args(value),
+ # Ruby 2.7 requires this to look like keyword args,
+ # and Ruby 1.9.3 doesn't understand keyword args, so
+ # don't use hash rockets here and both will be happy.
+ invalid: :replace, undef: :replace, replace: '' # rubocop:disable Style/HashSyntax
+ )
end
object.is_a?(Symbol) ? encoded_value.to_sym : encoded_value
end
@@ -52,10 +57,9 @@
end
def encoding_args(value)
args = [UTF8]
args << BINARY if ASCII_ENCODINGS.include?(value.encoding)
- args << ENCODING_OPTIONS
args
end
end
end