Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions rb/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ PATH
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
rubyzip (>= 1.2.2, < 4.0)
websocket (~> 1.0)

GEM
Expand Down Expand Up @@ -147,7 +147,7 @@ GEM
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
ruby-progressbar (1.13.0)
rubyzip (2.4.1)
rubyzip (3.0.0)
securerandom (0.4.1)
steep (1.5.3)
activesupport (>= 5.1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ def download_file(file_name, target_directory)

begin
Zip::File.open("#{file_name}.zip") do |zip|
zip.each { |entry| zip.extract(entry, "#{target_directory}#{file_name}") }
zip.each do |entry|
if Zipper::RUBYZIP_V3
zip.extract(entry, file_name, destination_directory: target_directory)
else
zip.extract(entry, "#{target_directory}#{file_name}")
end
end
end
ensure
FileUtils.rm_f("#{file_name}.zip")
Expand Down
14 changes: 12 additions & 2 deletions rb/lib/selenium/webdriver/common/zipper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# under the License.

require 'zip'
require 'zip/version' # Not required automatically
require 'tempfile'
require 'find'
require 'base64'
Expand All @@ -30,6 +31,7 @@ module WebDriver

module Zipper
EXTENSIONS = %w[.zip .xpi].freeze
RUBYZIP_V3 = Zip::VERSION >= '3.0.0'

class << self
def unzip(path)
Expand All @@ -42,7 +44,11 @@ def unzip(path)
dirname = File.dirname(to)

FileUtils.mkdir_p dirname
zip.extract(entry, to)
if RUBYZIP_V3
zip.extract(entry, entry.name, destination_directory: destination)
else
zip.extract(entry, to)
end
end
end

Expand Down Expand Up @@ -75,7 +81,11 @@ def with_tmp_zip(&blk)
# Don't use Tempfile since it lacks rb_file_s_rename permission on Windows.
Dir.mktmpdir do |tmp_dir|
zip_path = File.join(tmp_dir, 'webdriver-zip')
Zip::File.open(zip_path, Zip::File::CREATE, &blk)
if RUBYZIP_V3
Zip::File.open(zip_path, create: true, &blk)
else
Zip::File.open(zip_path, Zip::File::CREATE, &blk)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion rb/selenium-webdriver.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Gem::Specification.new do |s|
s.add_dependency 'base64', ['~> 0.2']
s.add_dependency 'logger', ['~> 1.4']
s.add_dependency 'rexml', ['~> 3.2', '>= 3.2.5']
s.add_dependency 'rubyzip', ['>= 1.2.2', '< 3.0']
s.add_dependency 'rubyzip', ['>= 1.2.2', '< 4.0']
s.add_dependency 'websocket', ['~> 1.0']

s.add_development_dependency 'git', ['~> 1.19']
Expand Down