From d829fa2d61569369986644ad8c35fb31a8c8cca8 Mon Sep 17 00:00:00 2001 From: Ryan Davis Date: Wed, 6 Nov 2019 14:40:54 -0800 Subject: [PATCH] Changed FileProvider to try to encode UTF-8 and convert newlines. For Windows compatibility. --- lib/inspec/file_provider.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/inspec/file_provider.rb b/lib/inspec/file_provider.rb index 971abdc42..7b402c8c2 100644 --- a/lib/inspec/file_provider.rb +++ b/lib/inspec/file_provider.rb @@ -123,6 +123,7 @@ module Inspec end def read(file) + # TODO: this is inefficient @contents[file] ||= read_from_zip(file) end @@ -141,6 +142,10 @@ module Inspec next unless file == entry.name res = io.read + try = res.dup + try.force_encoding Encoding::UTF_8 + res = try.encode(try.encoding, universal_newline: true) if try.valid_encoding? + break end end @@ -174,7 +179,8 @@ module Inspec res = entry.read || "" try = res.dup try.force_encoding Encoding::UTF_8 - res = try if try.valid_encoding? + res = try.encode(try.encoding, universal_newline: true) if + try.valid_encoding? res end end