diff --git a/lib/fluent/command/ctl.rb b/lib/fluent/command/ctl.rb index f908d40f05..11e59c9a30 100644 --- a/lib/fluent/command/ctl.rb +++ b/lib/fluent/command/ctl.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -67,7 +69,7 @@ def initialize(argv = ARGV) end def help_text - text = "\n" + text = +"\n" if Fluent.windows? text << "Usage: #{$PROGRAM_NAME} COMMAND [PID_OR_SVCNAME]\n" else diff --git a/lib/fluent/command/plugin_config_formatter.rb b/lib/fluent/command/plugin_config_formatter.rb index 00d660da0b..7540733d8d 100644 --- a/lib/fluent/command/plugin_config_formatter.rb +++ b/lib/fluent/command/plugin_config_formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -79,7 +81,7 @@ def call private def dump_txt(dumped_config) - dumped = "" + dumped = +"" plugin_helpers = dumped_config.delete(:plugin_helpers) if plugin_helpers && !plugin_helpers.empty? dumped << "helpers: #{plugin_helpers.join(',')}\n" @@ -101,7 +103,7 @@ def dump_txt(dumped_config) end def dump_section_txt(base_section, level = 0) - dumped = "" + dumped = +"" indent = " " * level if base_section[:section] sections = [] @@ -135,10 +137,10 @@ def dump_section_txt(base_section, level = 0) end def dump_markdown(dumped_config) - dumped = "" + dumped = +"" plugin_helpers = dumped_config.delete(:plugin_helpers) if plugin_helpers && !plugin_helpers.empty? - dumped = "## Plugin helpers\n\n" + dumped = +"## Plugin helpers\n\n" plugin_helpers.each do |plugin_helper| dumped << "* #{plugin_helper_markdown_link(plugin_helper)}\n" end @@ -156,7 +158,7 @@ def dump_markdown(dumped_config) end def dump_section_markdown(base_section, level = 0) - dumped = "" + dumped = +"" if base_section[:section] sections = [] params = base_section diff --git a/lib/fluent/compat/record_filter_mixin.rb b/lib/fluent/compat/record_filter_mixin.rb index 38a554d8bb..a421f30b2c 100644 --- a/lib/fluent/compat/record_filter_mixin.rb +++ b/lib/fluent/compat/record_filter_mixin.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -21,7 +23,7 @@ def filter_record(tag, time, record) end def format_stream(tag, es) - out = '' + out = +'' es.each {|time,record| tag_temp = tag.dup filter_record(tag_temp, time, record) diff --git a/lib/fluent/config/element.rb b/lib/fluent/config/element.rb index c61eb391cb..e53fb80ea7 100644 --- a/lib/fluent/config/element.rb +++ b/lib/fluent/config/element.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -141,7 +143,7 @@ def check_not_fetched(&block) def to_s(nest = 0) indent = " " * nest nindent = " " * (nest + 1) - out = "" + out = +"" if @arg.nil? || @arg.empty? out << "#{indent}<#{@name}>\n" else @@ -230,7 +232,7 @@ def dump_value(k, v, nindent) end def self.unescape_parameter(v) - result = '' + result = +'' v.each_char { |c| result << LiteralParser.unescape_char(c) } result end diff --git a/lib/fluent/config/literal_parser.rb b/lib/fluent/config/literal_parser.rb index 5664986481..f34066dff8 100644 --- a/lib/fluent/config/literal_parser.rb +++ b/lib/fluent/config/literal_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -228,8 +230,8 @@ def scan_json(is_array) # Yajl does not raise ParseError for incomplete json string, like '[1', '{"h"', '{"h":' or '{"h1":1' # This is the reason to use JSON module. - buffer = (is_array ? "[" : "{") - line_buffer = "" + buffer = +(is_array ? "[" : "{") + line_buffer = +"" until result char = getch @@ -252,7 +254,7 @@ def scan_json(is_array) # ignore comment char end buffer << line_buffer + "\n" - line_buffer = "" + line_buffer = +"" else # '#' is a char in json string line_buffer << char @@ -263,7 +265,7 @@ def scan_json(is_array) if char == "\n" buffer << line_buffer + "\n" - line_buffer = "" + line_buffer = +"" next end diff --git a/lib/fluent/config/types.rb b/lib/fluent/config/types.rb index 9c9ba89c8d..b1458ebbee 100644 --- a/lib/fluent/config/types.rb +++ b/lib/fluent/config/types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -100,7 +102,7 @@ def self.string_value(val, opts = {}, name = nil) return nil if val.nil? v = val.to_s - v = v.frozen? ? v.dup : v # config_param can't assume incoming string is mutable + v = v.frozen? ? v.dup : +v # config_param can't assume incoming string is mutable v.force_encoding(Encoding::UTF_8) end diff --git a/lib/fluent/log.rb b/lib/fluent/log.rb index f8175fd911..69d632870a 100644 --- a/lib/fluent/log.rb +++ b/lib/fluent/log.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -550,7 +552,7 @@ def get_worker_id(type) def event(level, args) time = Time.now - message = @optional_header ? @optional_header.dup : '' + message = @optional_header ? @optional_header.dup : +'' map = @optional_attrs ? @optional_attrs.dup : {} args.each {|a| if a.is_a?(Hash) diff --git a/lib/fluent/match.rb b/lib/fluent/match.rb index 7b6c076adc..79d0330f62 100644 --- a/lib/fluent/match.rb +++ b/lib/fluent/match.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -43,7 +45,7 @@ def initialize(pat) end stack = [] - regex = [''] + regex = [+''] escape = false dot = false @@ -105,7 +107,7 @@ def initialize(pat) elsif c == "{" # or stack.push [] - regex.push '' + regex.push +'' elsif c == "}" && !stack.empty? stack.last << regex.pop diff --git a/lib/fluent/plugin/buffer/file_chunk.rb b/lib/fluent/plugin/buffer/file_chunk.rb index 7930574a58..7373e8b68d 100644 --- a/lib/fluent/plugin/buffer/file_chunk.rb +++ b/lib/fluent/plugin/buffer/file_chunk.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -24,7 +26,7 @@ class Buffer class FileChunk < Chunk class FileChunkError < StandardError; end - BUFFER_HEADER = "\xc1\x00".force_encoding(Encoding::ASCII_8BIT).freeze + BUFFER_HEADER = (+"\xc1\x00").force_encoding(Encoding::ASCII_8BIT).freeze ### buffer path user specified : /path/to/directory/user_specified_prefix.*.log ### buffer chunk path : /path/to/directory/user_specified_prefix.b513b61c9791029c2513b61c9791029c2.log diff --git a/lib/fluent/plugin/buffer/memory_chunk.rb b/lib/fluent/plugin/buffer/memory_chunk.rb index 556c8c8a3d..ebd4a8a633 100644 --- a/lib/fluent/plugin/buffer/memory_chunk.rb +++ b/lib/fluent/plugin/buffer/memory_chunk.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -22,7 +24,7 @@ class Buffer class MemoryChunk < Chunk def initialize(metadata, compress: :text) super - @chunk = ''.force_encoding(Encoding::ASCII_8BIT) + @chunk = (+'').force_encoding(Encoding::ASCII_8BIT) @chunk_bytes = 0 @adding_bytes = 0 @adding_size = 0 @@ -68,7 +70,7 @@ def empty? def purge super - @chunk = ''.force_encoding("ASCII-8BIT") + @chunk = (+'').force_encoding("ASCII-8BIT") @chunk_bytes = @size = @adding_bytes = @adding_size = 0 true end diff --git a/lib/fluent/plugin/compressable.rb b/lib/fluent/plugin/compressable.rb index aa242478fe..73fcf94d21 100644 --- a/lib/fluent/plugin/compressable.rb +++ b/lib/fluent/plugin/compressable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -57,7 +59,7 @@ def decompress(compressed_data = nil, output_io: nil, input_io: nil) def string_decompress(compressed_data) io = StringIO.new(compressed_data) - out = '' + out = +'' loop do gz = Zlib::GzipReader.new(io) out << gz.read diff --git a/lib/fluent/plugin/formatter_csv.rb b/lib/fluent/plugin/formatter_csv.rb index 74760a1df7..6bc33db816 100644 --- a/lib/fluent/plugin/formatter_csv.rb +++ b/lib/fluent/plugin/formatter_csv.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -50,13 +52,13 @@ def configure(conf) end @generate_opts = {col_sep: @delimiter, force_quotes: @force_quotes, headers: @fields, - row_sep: @add_newline ? :auto : "".force_encoding(Encoding::ASCII_8BIT)} + row_sep: @add_newline ? :auto : (+"").force_encoding(Encoding::ASCII_8BIT)} # Cache CSV object per thread to avoid internal state sharing @cache = {} end def format(tag, time, record) - csv = (@cache[Thread.current] ||= CSV.new("".force_encoding(Encoding::ASCII_8BIT), **@generate_opts)) + csv = (@cache[Thread.current] ||= CSV.new((+"").force_encoding(Encoding::ASCII_8BIT), **@generate_opts)) line = (csv << record).string.dup # Need manual cleanup because CSV writer doesn't provide such method. csv.rewind @@ -65,7 +67,7 @@ def format(tag, time, record) end def format_with_nested_fields(tag, time, record) - csv = (@cache[Thread.current] ||= CSV.new("".force_encoding(Encoding::ASCII_8BIT), **@generate_opts)) + csv = (@cache[Thread.current] ||= CSV.new((+"").force_encoding(Encoding::ASCII_8BIT), **@generate_opts)) values = @accessors.map { |a| a.call(record) } line = (csv << values).string.dup # Need manual cleanup because CSV writer doesn't provide such method. diff --git a/lib/fluent/plugin/formatter_ltsv.rb b/lib/fluent/plugin/formatter_ltsv.rb index 76100bb91b..1bf054ecdf 100644 --- a/lib/fluent/plugin/formatter_ltsv.rb +++ b/lib/fluent/plugin/formatter_ltsv.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -31,7 +33,7 @@ class LabeledTSVFormatter < Formatter config_param :add_newline, :bool, default: true def format(tag, time, record) - formatted = "" + formatted = +"" record.each do |label, value| formatted << @delimiter if formatted.length.nonzero? formatted << "#{label}#{@label_delimiter}#{value.to_s.gsub(@delimiter, @replacement)}" diff --git a/lib/fluent/plugin/formatter_out_file.rb b/lib/fluent/plugin/formatter_out_file.rb index 364303000a..bb853d5150 100644 --- a/lib/fluent/plugin/formatter_out_file.rb +++ b/lib/fluent/plugin/formatter_out_file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -43,7 +45,7 @@ def configure(conf) end def format(tag, time, record) - header = '' + header = +'' header << "#{@timef.format(time)}#{@delimiter}" if @output_time header << "#{tag}#{@delimiter}" if @output_tag "#{header}#{Yajl.dump(record)}#{@newline}" diff --git a/lib/fluent/plugin/in_http.rb b/lib/fluent/plugin/in_http.rb index 6385a80a79..40683933ba 100644 --- a/lib/fluent/plugin/in_http.rb +++ b/lib/fluent/plugin/in_http.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -56,7 +58,7 @@ class HttpInput < Input helpers :parser, :compat_parameters, :event_loop, :server - EMPTY_GIF_IMAGE = "GIF89a\u0001\u0000\u0001\u0000\x80\xFF\u0000\xFF\xFF\xFF\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;".force_encoding("UTF-8") + EMPTY_GIF_IMAGE = (+"GIF89a\u0001\u0000\u0001\u0000\x80\xFF\u0000\xFF\xFF\xFF\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;").force_encoding("UTF-8") desc 'The port to listen to.' config_param :port, :integer, default: 9880 diff --git a/lib/fluent/plugin/in_monitor_agent.rb b/lib/fluent/plugin/in_monitor_agent.rb index f41c1a0bce..0654f7b7d2 100644 --- a/lib/fluent/plugin/in_monitor_agent.rb +++ b/lib/fluent/plugin/in_monitor_agent.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -102,7 +104,7 @@ def render_json(obj, code: 200, pretty_json: nil) def render_ltsv(obj, code: 200) normalized = JSON.parse(obj.to_json) - text = '' + text = +'' normalized.each do |hash| row = [] hash.each do |k, v| diff --git a/lib/fluent/plugin/in_syslog.rb b/lib/fluent/plugin/in_syslog.rb index 28ad1c5dd9..f975b60d6c 100644 --- a/lib/fluent/plugin/in_syslog.rb +++ b/lib/fluent/plugin/in_syslog.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # diff --git a/lib/fluent/plugin/in_tail.rb b/lib/fluent/plugin/in_tail.rb index 852f2723bd..8b84e54a0a 100644 --- a/lib/fluent/plugin/in_tail.rb +++ b/lib/fluent/plugin/in_tail.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -1010,7 +1012,7 @@ def initialize(from_encoding, encoding, log, max_line_size=nil) @from_encoding = from_encoding @encoding = encoding @need_enc = from_encoding != encoding - @buffer = ''.force_encoding(from_encoding) + @buffer = (+'').force_encoding(from_encoding) @eol = "\n".encode(from_encoding).freeze @max_line_size = max_line_size @skip_current_line = false @@ -1032,6 +1034,7 @@ def <<(chunk) # quad-byte encoding to IO#readpartial as the second arguments results in an # assertion failure on Ruby < 2.4.0 for unknown reasons. orig_encoding = chunk.encoding + +chunk chunk.force_encoding(from_encoding) @buffer << chunk # Thus the encoding needs to be reverted back here @@ -1118,7 +1121,7 @@ def initialize(watcher, path:, read_lines_limit:, read_bytes_limit_per_second:, @receive_lines = receive_lines @open_on_every_update = open_on_every_update @fifo = FIFO.new(from_encoding || Encoding::ASCII_8BIT, encoding || Encoding::ASCII_8BIT, log, max_line_size) - @iobuf = ''.force_encoding('ASCII-8BIT') + @iobuf = (+'').force_encoding('ASCII-8BIT') @lines = [] @io = nil @notify_mutex = Mutex.new diff --git a/lib/fluent/plugin_helper/server.rb b/lib/fluent/plugin_helper/server.rb index eecee5ae7e..b64bcbc601 100644 --- a/lib/fluent/plugin_helper/server.rb +++ b/lib/fluent/plugin_helper/server.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -675,7 +677,7 @@ def initialize(sock, context, socket_option_setter, close_callback, log, under_p socket_option_setter.call(sock) @_handler_socket = OpenSSL::SSL::SSLSocket.new(sock, context) @_handler_socket.sync_close = true - @_handler_write_buffer = ''.force_encoding('ascii-8bit') + @_handler_write_buffer = (+'').force_encoding('ascii-8bit') @_handler_accepted = false super(@_handler_socket) diff --git a/lib/fluent/test/output_test.rb b/lib/fluent/test/output_test.rb index bb18884dc2..e5571096fe 100644 --- a/lib/fluent/test/output_test.rb +++ b/lib/fluent/test/output_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # # Fluentd # @@ -116,7 +118,7 @@ def emit(record, time=EventTime.now) end def expect_format(str) - (@expected_buffer ||= '') << str + (@expected_buffer ||= +'') << str end def run(&block) @@ -124,7 +126,7 @@ def run(&block) super { block.call if block - buffer = '' + buffer = +'' lines = {} # v0.12 TimeSlicedOutput doesn't call #format_stream @entries.each do |time, record|