Skip to content

Commit

Permalink
Add all regex ruby support to set encode
Browse files Browse the repository at this point in the history
Signed-off-by: Yuta Iwama <ganmacs@gmail.com>
  • Loading branch information
ganmacs committed Feb 4, 2020
1 parent 8bece39 commit f511546
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
20 changes: 5 additions & 15 deletions lib/fluent/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -871,28 +871,18 @@ def build_system_config(conf)
system_config
end

RUBY_ENCODING_OPTIONS_REGEX = %r{\A(-E|--encoding=|--internal-encoding=|--external-encoding=)}.freeze

def build_spawn_command
fluentd_spawn_cmd = [ServerEngine.ruby_bin_path]

rubyopt = ENV['RUBYOPT']
if rubyopt
encodes, others = rubyopt.split(' ').partition { |e| e.match?('\A-E') }
encodes, others = rubyopt.split(' ').partition { |e| e.match?(RUBY_ENCODING_OPTIONS_REGEX) }
fluentd_spawn_cmd.concat(others)

adopted_encode =
if encodes.size >= 1
r = encodes.pop
unless encodes.empty?
drop = encodes.join(', ')
$log.warn("Encoding option #{drop} is(are) ignored")
end

r
else
'-Eascii-8bit:ascii-8bit'
end

fluentd_spawn_cmd << adopted_encode
adopted_encodes = encodes.empty? ? ['-Eascii-8bit:ascii-8bit'] : encodes
fluentd_spawn_cmd.concat(adopted_encodes)
else
fluentd_spawn_cmd << '-Eascii-8bit:ascii-8bit'
end
Expand Down
12 changes: 9 additions & 3 deletions test/command/test_fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,13 @@ def multi_workers_ready?
)
end

test "-E option is set to RUBYOPT" do
data(
'-E' => '-Eutf-8',
'-encoding' => '--encoding=utf-8',
'-external-encoding' => '--external-encoding=utf-8',
'-internal-encoding' => '--internal-encoding=utf-8',
)
test "-E option is set to RUBYOPT3" do |opt|
conf = <<CONF
<source>
@type dummy
Expand All @@ -810,9 +816,9 @@ def multi_workers_ready?
conf_path = create_conf_file('rubyopt_test.conf', conf)
assert_log_matches(
create_cmdline(conf_path),
'-Eutf-8',
*opt.split(' '),
patterns_not_match: ['-Eascii-8bit:ascii-8bit'],
env: { 'RUBYOPT' => '-Eutf-8' },
env: { 'RUBYOPT' => opt },
)
end

Expand Down

0 comments on commit f511546

Please sign in to comment.