Skip to content

Commit

Permalink
Merge pull request #9 from chef/tm/silly_paths
Browse files Browse the repository at this point in the history
Ensure that paths like foo..bar.baz aren't ignored
  • Loading branch information
lamont-granquist authored Aug 3, 2018
2 parents de1c1df + 3194d97 commit 746470b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 11 additions & 1 deletion lib/mixlib/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def create(files = [], gzip: false)
end

def extract(destination, perms: true, ignore: [])
ignore = [/^\.$/, /\.{2}/] + Array(ignore)
ignore = [/^\.$/, /\.{2}#{path_separator}/] + Array(ignore)

create_and_empty(destination)

Expand All @@ -49,6 +49,16 @@ def extract(destination, perms: true, ignore: [])

private

BACKSLASH = '\\'.freeze

def path_separator
if Gem.win_platform?
File::ALT_SEPARATOR || BACKSLASH
else
File::SEPARATOR
end
end

def create_and_empty(destination)
FileUtils.mkdir_p(destination)
if @empty
Expand Down
8 changes: 4 additions & 4 deletions spec/mixlib/archive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,22 @@
end

it "runs the extractor" do
expect(archiver).to receive(:extract).with(destination, { perms: true, ignore: [/^\.$/, /\.{2}/] })
expect(archiver).to receive(:extract).with(destination, { perms: true, ignore: [/^\.$/, /\.{2}\//] })
archive.extract(destination)
end

it "passes options to the extractor" do
expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}/] })
expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}\//] })
archive.extract(destination, perms: false)
end

it "allows the user to ignore more patterns" do
expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}/, /^$/] })
expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}\//, /^$/] })
archive.extract(destination, perms: false, ignore: [/^$/])
end

it "accepts a single ignore pattern" do
expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}/, /^$/] })
expect(archiver).to receive(:extract).with(destination, { perms: false, ignore: [/^\.$/, /\.{2}\//, /^$/] })
archive.extract(destination, perms: false, ignore: /^$/)
end
end
Expand Down

0 comments on commit 746470b

Please sign in to comment.