Changed FileProvider to try to encode UTF-8 and convert newlines.

For Windows compatibility.
This commit is contained in:
Ryan Davis 2019-11-06 14:40:54 -08:00
parent 4242937bea
commit d829fa2d61

View file

@ -123,6 +123,7 @@ module Inspec
end end
def read(file) def read(file)
# TODO: this is inefficient
@contents[file] ||= read_from_zip(file) @contents[file] ||= read_from_zip(file)
end end
@ -141,6 +142,10 @@ module Inspec
next unless file == entry.name next unless file == entry.name
res = io.read 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 break
end end
end end
@ -174,7 +179,8 @@ module Inspec
res = entry.read || "" res = entry.read || ""
try = res.dup try = res.dup
try.force_encoding Encoding::UTF_8 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 res
end end
end end