Skip to content

Commit

Permalink
zcat on macOS does not accept a file path argument (issue #23).
Browse files Browse the repository at this point in the history
  • Loading branch information
postmodern committed Aug 4, 2023
1 parent 08f3954 commit c831585
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/wordlist/compression/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def self.command(path, format: )
raise(UnknownFormat,"unsupported format: #{format.inspect}")
end

Shellwords.shelljoin([command, path])
"#{command} < #{Shellwords.shellescape(path)}"
end

#
Expand Down
26 changes: 13 additions & 13 deletions spec/compression/reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,47 @@
context "when given format: :gzip" do
subject { described_class.command(path, format: :gzip) }

it "must return 'zcat path/to/file'" do
expect(subject).to eq("zcat #{path}")
it "must return 'zcat < path/to/file'" do
expect(subject).to eq("zcat < #{path}")
end

context "and the file contains special characters" do
let(:path) { 'path/to/the file' }

it "must shellescape them" do
expect(subject).to eq("zcat #{Shellwords.shellescape(path)}")
expect(subject).to eq("zcat < #{Shellwords.shellescape(path)}")
end
end
end

context "when given format: :bzip2" do
subject { described_class.command(path, format: :bzip2) }

it "must return 'bzcat path/to/file'" do
expect(subject).to eq("bzcat #{path}")
it "must return 'bzcat < path/to/file'" do
expect(subject).to eq("bzcat < #{path}")
end

context "and the file contains special characters" do
let(:path) { 'path/to/the file' }

it "must shellescape them" do
expect(subject).to eq("bzcat #{Shellwords.shellescape(path)}")
expect(subject).to eq("bzcat < #{Shellwords.shellescape(path)}")
end
end
end

context "when given format: :xz" do
subject { described_class.command(path, format: :xz) }

it "must return 'xzcat path/to/file'" do
expect(subject).to eq("xzcat #{path}")
it "must return 'xzcat < path/to/file'" do
expect(subject).to eq("xzcat < #{path}")
end

context "and the file contains special characters" do
let(:path) { 'path/to/the file' }

it "must shellescape them" do
expect(subject).to eq("xzcat #{Shellwords.shellescape(path)}")
expect(subject).to eq("xzcat < #{Shellwords.shellescape(path)}")
end
end
end
Expand All @@ -69,7 +69,7 @@

context "when given format: :gzip" do
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.gz') }
let(:expected_contents) { `zcat #{Shellwords.shellescape(path)}` }
let(:expected_contents) { `zcat < #{Shellwords.shellescape(path)}` }

subject { described_class.open(path, format: :gzip) }

Expand All @@ -86,7 +86,7 @@

context "when given format: :bzip2" do
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.bz2') }
let(:expected_contents) { `bzcat #{Shellwords.shellescape(path)}` }
let(:expected_contents) { `bzcat < #{Shellwords.shellescape(path)}` }

subject { described_class.open(path, format: :bzip2) }

Expand All @@ -103,7 +103,7 @@

context "when given format: :xz" do
let(:path) { ::File.join(fixtures_dir,'wordlist.txt.xz') }
let(:expected_contents) { `xzcat #{Shellwords.shellescape(path)}` }
let(:expected_contents) { `xzcat < #{Shellwords.shellescape(path)}` }

subject { described_class.open(path, format: :xz) }

Expand All @@ -120,7 +120,7 @@

context "when the command is not installed" do
let(:format) { :gzip }
let(:command) { Shellwords.shelljoin(['zcat', path]) }
let(:command) { "zcat < #{Shellwords.shellescape(path)}" }
let(:path) { 'path/to/wordlist.gz' }

before do
Expand Down

0 comments on commit c831585

Please sign in to comment.