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
|
# This software may be modified and distributed under the terms
|
||||||
# of the MIT license. See the LICENSE.txt file for details.
|
# of the MIT license. See the LICENSE.txt file for details.
|
||||||
|
|
||||||
|
require 'rackstash/helpers'
|
||||||
|
|
||||||
module Rackstash
|
module Rackstash
|
||||||
# This class and all its data are immutable after initialization
|
# This class and all its data are immutable after initialization
|
||||||
class Message
|
class Message
|
||||||
|
include Rackstash::Helpers::UTF8
|
||||||
|
|
||||||
attr_reader :message
|
attr_reader :message
|
||||||
|
|
||||||
alias as_json 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
|
# Sanitize a single mesage to be added to the buffer, can be a single or
|
||||||
# multi line string
|
# 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
|
# @return [String] the sanitized frozen message
|
||||||
def cleanup(msg)
|
def cleanup(msg)
|
||||||
msg = msg.inspect unless msg.is_a?(String)
|
msg = msg.inspect unless msg.is_a?(String)
|
||||||
msg = utf8_encode(msg)
|
utf8_encode(msg)
|
||||||
msg.freeze
|
|
||||||
end
|
|
||||||
|
|
||||||
def utf8_encode(str)
|
|
||||||
str.to_s.encode(
|
|
||||||
Encoding::UTF_8,
|
|
||||||
invalid: :replace,
|
|
||||||
undef: :replace
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def dup_freeze(obj)
|
def dup_freeze(obj)
|
||||||
|
|||||||
@ -42,7 +42,7 @@ describe Rackstash::Message do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'dups and freezes all messages' do
|
it 'dups and freezes all messages' do
|
||||||
str = 'hello'
|
str = String.new('hello')
|
||||||
expect(str.encoding).to eql Encoding::UTF_8
|
expect(str.encoding).to eql Encoding::UTF_8
|
||||||
|
|
||||||
message = described_class.new(str)
|
message = described_class.new(str)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user