Skip to content

Commit 4734262

Browse files
committed
encoding
Signed-off-by: Shizuo Fujita <fujita@clear-code.com>
1 parent 6821e4b commit 4734262

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/fluent/plugin/in_tail.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,10 @@ class FIFO
10341034
def initialize(from_encoding, encoding, log, max_line_size=nil)
10351035
@from_encoding = from_encoding
10361036
@encoding = encoding
1037-
@need_enc = from_encoding != encoding
1038-
@buffer = ''.force_encoding(from_encoding)
1039-
@eol = "\n".encode(from_encoding).freeze
1037+
@encoding_for_appending = from_encoding || encoding || Encoding::ASCII_8BIT
1038+
@need_enc = from_encoding && encoding && (from_encoding != encoding)
1039+
@buffer = ''.force_encoding(@encoding_for_appending)
1040+
@eol = "\n".encode(@encoding_for_appending).freeze
10401041
@max_line_size = max_line_size
10411042
@skip_current_line = false
10421043
@skipping_current_line_bytesize = 0
@@ -1057,7 +1058,7 @@ def <<(chunk)
10571058
# quad-byte encoding to IO#readpartial as the second arguments results in an
10581059
# assertion failure on Ruby < 2.4.0 for unknown reasons.
10591060
orig_encoding = chunk.encoding
1060-
chunk.force_encoding(from_encoding)
1061+
chunk.force_encoding(@encoding_for_appending)
10611062
@buffer << chunk
10621063
# Thus the encoding needs to be reverted back here
10631064
chunk.force_encoding(orig_encoding)
@@ -1143,7 +1144,7 @@ def initialize(watcher, path:, read_lines_limit:, read_bytes_limit_per_second:,
11431144
@read_bytes_limit_per_second = read_bytes_limit_per_second
11441145
@receive_lines = receive_lines
11451146
@open_on_every_update = open_on_every_update
1146-
@fifo = FIFO.new(from_encoding || Encoding::ASCII_8BIT, encoding || Encoding::ASCII_8BIT, log, max_line_size)
1147+
@fifo = FIFO.new(from_encoding, encoding, log, max_line_size)
11471148
@lines = []
11481149
@io = nil
11491150
@notify_mutex = Mutex.new

0 commit comments

Comments
 (0)