Skip to content

[rb] Allow to use rubyzip v3 #16108

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

Merged
merged 3 commits into from
Aug 10, 2025
Merged

Conversation

Earlopain
Copy link
Contributor

@Earlopain Earlopain commented Jul 30, 2025

User description

💥 What does this PR do?

Allow to use rubyzip v3. 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

Closes #16111

🔧 Implementation Notes

Almost everything is already abstracted away behind he upper module, so the needed changes are rather small.

🔄 Types of changes

  • Maintenance, I guess?

PR Type

Enhancement


Description

  • Update rubyzip dependency to support version 3.x

  • Add version detection for backward compatibility

  • Modify zip extraction methods for API changes

  • Update gemspec dependency constraint


Diagram Walkthrough

flowchart LR
  A["rubyzip v2 API"] --> B["Version Detection"]
  B --> C["Conditional Logic"]
  C --> D["rubyzip v3 API"]
  E["Gemspec Update"] --> F["Support v3.x"]
Loading

File Walkthrough

Relevant files
Enhancement
has_file_downloads.rb
Add rubyzip v3 compatibility to file downloads                     

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

  • Add conditional logic for rubyzip v3 compatibility
  • Update zip extraction method calls with new API
+7/-1     
zipper.rb
Implement rubyzip v3 compatibility layer                                 

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

  • Add version detection constant RUBYZIP_V3
  • Update zip extraction and creation methods
  • Add conditional API calls for backward compatibility
+12/-2   
Dependencies
selenium-webdriver.gemspec
Allow rubyzip version 3.x in dependencies                               

rb/selenium-webdriver.gemspec

  • Update rubyzip dependency constraint from < 3.0 to < 4.0
+1/-1     

@selenium-ci selenium-ci added the C-rb Ruby Bindings label Jul 30, 2025
@Earlopain Earlopain marked this pull request as ready for review July 30, 2025 07:58
Copy link
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Logic Error

The extraction logic appears incorrect - in the v3 branch, file_name is passed as the second parameter instead of the full path, which may cause files to be extracted to wrong locations or with wrong names.

  zip.extract(entry, file_name, destination_directory: target_directory)
else
  zip.extract(entry, "#{target_directory}#{file_name}")
API Inconsistency

The v3 extraction method only uses destination_directory parameter but ignores the calculated to path, potentially breaking the existing file structure and naming logic.

  zip.extract(entry, destination_directory: destination)
else
  zip.extract(entry, to)

Copy link
Contributor

qodo-merge-pro bot commented Jul 30, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Correct rubyzip v3 extraction parameters

The rubyzip v3 extraction parameters are incorrect. The second parameter should
be the entry name, not the file name, to maintain consistent extraction
behavior.

rb/lib/selenium/webdriver/common/driver_extensions/has_file_downloads.rb [43-47]

 if Zipper::RUBYZIP_V3
-  zip.extract(entry, file_name, destination_directory: target_directory)
+  zip.extract(entry, entry.name, destination_directory: "#{target_directory}#{file_name}")
 else
   zip.extract(entry, "#{target_directory}#{file_name}")
 end
  • Apply / Chat
Suggestion importance[1-10]: 9

__

Why: This suggestion correctly identifies a bug where the downloaded file would be extracted with an incorrect name (file_name instead of entry.name), and provides a fix that ensures consistent behavior across rubyzip versions.

High
Fix rubyzip v3 extraction path

The rubyzip v3 API change breaks the extraction logic. The destination_directory
parameter should be combined with the entry name to maintain the same file
structure as the v2 behavior.

rb/lib/selenium/webdriver/common/zipper.rb [47-51]

 if RUBYZIP_V3
-  zip.extract(entry, destination_directory: destination)
+  zip.extract(entry, entry.name, destination_directory: destination)
 else
   zip.extract(entry, to)
 end
  • Apply / Chat
Suggestion importance[1-10]: 3

__

Why: The suggestion is correct that the improved code works, but the original code is also correct because the dest_path argument in zip.extract defaults to entry.name in rubyzip v3, making the change redundant.

Low
  • Update

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.
@Earlopain Earlopain force-pushed the rb-allow-rubyzip-v3 branch from 6b19fe6 to b91463c Compare July 30, 2025 08:13
@aguspe
Copy link
Contributor

aguspe commented Aug 10, 2025

@Earlopain thank you for your contribution!

@aguspe aguspe merged commit fa6bb2e into SeleniumHQ:trunk Aug 10, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: rubyzip 3.0.0 has been released; ruby Gemfile.lock constrains this to versions <3.0
3 participants