Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that paths like foo..bar.baz aren't ignored #9

Merged
merged 1 commit into from
Aug 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/mixlib/archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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 @@ -35,6 +35,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 @@ -58,22 +58,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