diff options
author | Tim Smith <tsmith@chef.io> | 2019-04-03 10:12:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-03 10:12:02 -0700 |
commit | 89651f74c468bad4844dbd983640edf6bd672bcd (patch) | |
tree | daba2694b124eb8a1f5d84ecdf09a3060af4860e | |
parent | cfe678b5d8365afdc53a222ca49f4c69e6bb03f3 (diff) | |
parent | 128e9dcb62015c2612e2d397d26f2dd334bcc843 (diff) | |
download | chef-89651f74c468bad4844dbd983640edf6bd672bcd.tar.gz |
Merge pull request #8337 from chef/lcg/fix-dc-utf8-file-output
fix data collector non-utf8 file output
-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 |