diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-04-03 09:36:40 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2019-04-03 09:42:19 -0700 |
commit | 128e9dcb62015c2612e2d397d26f2dd334bcc843 (patch) | |
tree | 3a0843580725c85920c0f52d95980dad068aeb55 | |
parent | 6837d6bda9fbfdcab0c2d26f3313ec106137e203 (diff) | |
download | chef-128e9dcb62015c2612e2d397d26f2dd334bcc843.tar.gz |
fix data collector non-utf8 file output
forces output to UTF-8 so it doesn't throw.
closes #8326
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/data_collector.rb | 2 | ||||
-rw-r--r-- | spec/unit/data_collector_spec.rb | 8 |
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/chef/data_collector.rb b/lib/chef/data_collector.rb index f445dc2ed9..1294231e24 100644 --- a/lib/chef/data_collector.rb +++ b/lib/chef/data_collector.rb @@ -218,7 +218,7 @@ class Chef # def send_to_file_location(file_name, message) File.open(file_name, "a") do |fh| - fh.puts Chef::JSONCompat.to_json(message) + fh.puts Chef::JSONCompat.to_json(message, validate_utf8: false) end end diff --git a/spec/unit/data_collector_spec.rb b/spec/unit/data_collector_spec.rb index 154ab4681c..fed0e54b45 100644 --- a/spec/unit/data_collector_spec.rb +++ b/spec/unit/data_collector_spec.rb @@ -871,4 +871,12 @@ describe Chef::DataCollector do end end + + describe "#send_to_file_location(file_name, message)" do + let(:tempfile) { Tempfile.new("rspec-chef-datacollector-out") } + let(:shift_jis) { "I have no idea what this character is:\n #{0x83.chr}#{0x80.chr}.\n" } + it "handles invalid UTF-8 properly" do + data_collector.send(:send_to_file_location, tempfile, { invalid: shift_jis }) + end + end end |