summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2019-04-03 09:36:40 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2019-04-03 09:42:19 -0700
commit128e9dcb62015c2612e2d397d26f2dd334bcc843 (patch)
tree3a0843580725c85920c0f52d95980dad068aeb55
parent6837d6bda9fbfdcab0c2d26f3313ec106137e203 (diff)
downloadchef-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.rb2
-rw-r--r--spec/unit/data_collector_spec.rb8
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