mirror of
https://github.com/meineerde/rackstash.git
synced 2025-10-17 14:01:01 +00:00
Use Rackstash::Helpers::UTF8 in Message class
This commit is contained in:
parent
d73b7ba8e1
commit
9fc9ea248b
@ -5,9 +5,13 @@
|
||||
# This software may be modified and distributed under the terms
|
||||
# of the MIT license. See the LICENSE.txt file for details.
|
||||
|
||||
require 'rackstash/helpers'
|
||||
|
||||
module Rackstash
|
||||
# This class and all its data are immutable after initialization
|
||||
class Message
|
||||
include Rackstash::Helpers::UTF8
|
||||
|
||||
attr_reader :message
|
||||
|
||||
alias as_json message
|
||||
@ -52,20 +56,11 @@ module Rackstash
|
||||
# Sanitize a single mesage to be added to the buffer, can be a single or
|
||||
# multi line string
|
||||
#
|
||||
# @param msg [#to_s] a message to be added to the buffer
|
||||
# @param msg [String, #inspect] a message to be added to the buffer
|
||||
# @return [String] the sanitized frozen message
|
||||
def cleanup(msg)
|
||||
msg = msg.inspect unless msg.is_a?(String)
|
||||
msg = utf8_encode(msg)
|
||||
msg.freeze
|
||||
end
|
||||
|
||||
def utf8_encode(str)
|
||||
str.to_s.encode(
|
||||
Encoding::UTF_8,
|
||||
invalid: :replace,
|
||||
undef: :replace
|
||||
)
|
||||
utf8_encode(msg)
|
||||
end
|
||||
|
||||
def dup_freeze(obj)
|
||||
|
||||
@ -42,7 +42,7 @@ describe Rackstash::Message do
|
||||
end
|
||||
|
||||
it 'dups and freezes all messages' do
|
||||
str = 'hello'
|
||||
str = String.new('hello')
|
||||
expect(str.encoding).to eql Encoding::UTF_8
|
||||
|
||||
message = described_class.new(str)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user