Merge pull request #4619 from inspec/zenspider/empty-tarball

Fix TarProvider when the tarball has empty files in it.
This commit is contained in:
Ryan Davis 2019-10-21 12:31:29 -07:00 committed by GitHub
commit dd3043a992
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View file

@ -171,7 +171,7 @@ module Inspec
path = Pathname.new(name).relative_path_from(here).to_s
@contents[path] = begin # not ||= in a tarball, last one wins
res = entry.read
res = entry.read || ""
try = res.dup
try.force_encoding Encoding::UTF_8
res = try if try.valid_encoding?

Binary file not shown.

View file

@ -185,6 +185,12 @@ describe Inspec::TarProvider do
it "must read the contents of the file" do
_(subject.read("inspec.yml")).must_match(/^name: complete$/)
end
it "deals with empty files in tarballs correctly" do
path = "test/fixtures/contains-empty-file-0.1.0.tar.gz"
f = Inspec::FileProvider.for_path(path)
_(f.files.grep(/empty/)).wont_be_empty
end
end
Entry = Struct.new(:full_name) do