From f51154699ca30485473c4097208148e91d15e3ab Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Tue, 4 Feb 2020 18:08:58 +0900 Subject: [PATCH] Add all regex ruby support to set encode Signed-off-by: Yuta Iwama --- lib/fluent/supervisor.rb | 20 +++++--------------- test/command/test_fluentd.rb | 12 +++++++++--- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 8e109310b1..2a972a4866 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -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 diff --git a/test/command/test_fluentd.rb b/test/command/test_fluentd.rb index e0972cdb53..8928424439 100644 --- a/test/command/test_fluentd.rb +++ b/test/command/test_fluentd.rb @@ -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 = < @type dummy @@ -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