Skip to content

Commit fa6bb2e

Browse files
Earlopainaguspe
andauthored
[rb] Allow to use rubyzip v3 (#16108)
After quite a while, it was finally released. There are a few breaking changes to be aware of: https://github.com/rubyzip/rubyzip/wiki/Updating-to-version-3.x Almost everything is already abstracted away behind he upper module, so the needed changes are rather small. Co-authored-by: Augustin Gottlieb <[email protected]>
1 parent ca1fc53 commit fa6bb2e

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

rb/Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PATH
77
base64 (~> 0.2)
88
logger (~> 1.4)
99
rexml (~> 3.2, >= 3.2.5)
10-
rubyzip (>= 1.2.2, < 3.0)
10+
rubyzip (>= 1.2.2, < 4.0)
1111
websocket (~> 1.0)
1212

1313
GEM
@@ -147,7 +147,7 @@ GEM
147147
lint_roller (~> 1.1)
148148
rubocop (~> 1.72, >= 1.72.1)
149149
ruby-progressbar (1.13.0)
150-
rubyzip (2.4.1)
150+
rubyzip (3.0.0)
151151
securerandom (0.4.1)
152152
steep (1.5.3)
153153
activesupport (>= 5.1)

rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ def download_file(file_name, target_directory)
3939

4040
begin
4141
Zip::File.open("#{file_name}.zip") do |zip|
42-
zip.each { |entry| zip.extract(entry, "#{target_directory}#{file_name}") }
42+
zip.each do |entry|
43+
if Zipper::RUBYZIP_V3
44+
zip.extract(entry, file_name, destination_directory: target_directory)
45+
else
46+
zip.extract(entry, "#{target_directory}#{file_name}")
47+
end
48+
end
4349
end
4450
ensure
4551
FileUtils.rm_f("#{file_name}.zip")

rb/lib/selenium/webdriver/common/zipper.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# under the License.
1919

2020
require 'zip'
21+
require 'zip/version' # Not required automatically
2122
require 'tempfile'
2223
require 'find'
2324
require 'base64'
@@ -30,6 +31,7 @@ module WebDriver
3031

3132
module Zipper
3233
EXTENSIONS = %w[.zip .xpi].freeze
34+
RUBYZIP_V3 = Zip::VERSION >= '3.0.0'
3335

3436
class << self
3537
def unzip(path)
@@ -42,7 +44,11 @@ def unzip(path)
4244
dirname = File.dirname(to)
4345

4446
FileUtils.mkdir_p dirname
45-
zip.extract(entry, to)
47+
if RUBYZIP_V3
48+
zip.extract(entry, entry.name, destination_directory: destination)
49+
else
50+
zip.extract(entry, to)
51+
end
4652
end
4753
end
4854

@@ -75,7 +81,11 @@ def with_tmp_zip(&blk)
7581
# Don't use Tempfile since it lacks rb_file_s_rename permission on Windows.
7682
Dir.mktmpdir do |tmp_dir|
7783
zip_path = File.join(tmp_dir, 'webdriver-zip')
78-
Zip::File.open(zip_path, Zip::File::CREATE, &blk)
84+
if RUBYZIP_V3
85+
Zip::File.open(zip_path, create: true, &blk)
86+
else
87+
Zip::File.open(zip_path, Zip::File::CREATE, &blk)
88+
end
7989
end
8090
end
8191

rb/selenium-webdriver.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Gem::Specification.new do |s|
5252
s.add_dependency 'base64', ['~> 0.2']
5353
s.add_dependency 'logger', ['~> 1.4']
5454
s.add_dependency 'rexml', ['~> 3.2', '>= 3.2.5']
55-
s.add_dependency 'rubyzip', ['>= 1.2.2', '< 3.0']
55+
s.add_dependency 'rubyzip', ['>= 1.2.2', '< 4.0']
5656
s.add_dependency 'websocket', ['~> 1.0']
5757

5858
s.add_development_dependency 'git', ['~> 1.19']

0 commit comments

Comments
 (0)