Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mmenanno
Copy link
Contributor

Summary

  • Adds cgi as an explicit runtime dependency to fix compatibility with Ruby 3.5+
  • Resolves issue where VCR fails due to CGI being removed from Ruby standard library

Problem

Ruby 3.5 removed CGI from the standard library, causing VCR to fail with:
undefined method 'parse' for class '#Class:CGI'

This occurs because VCR uses CGI.method(:parse) in lib/vcr/configuration.rb:505 for query string parsing.

Solution

Added spec.add_runtime_dependency 'cgi' to vcr.gemspec to ensure the CGI library is available across all supported Ruby versions.

Test plan

  • Verified gemspec builds successfully with gem build vcr.gemspec
  • Confirmed the change addresses the specific error mentioned in the issue

Fixes #1057

Fixes #1057. Ruby 3.5 removed CGI from the standard library, causing
VCR to fail when using CGI.parse for query parsing. Adding cgi as an
explicit runtime dependency ensures compatibility across Ruby versions.
Uses standard library URI.decode_www_form instead of requiring external
cgi dependency. Maintains identical API by converting array format to
the expected hash-of-arrays format that CGI.parse provides.

Fixes #1057
@mmenanno mmenanno changed the title Add cgi as runtime dependency for Ruby 3.5+ compatibility Replace CGI.parse with URI.decode_www_form for Ruby 3.5+ compatibility Aug 18, 2025
@mmenanno
Copy link
Contributor Author

I've updated this PR with an alternative solution that avoids adding any external dependencies.

Instead of adding cgi as a runtime dependency, this now uses URI.decode_www_form from Ruby's standard library, which remains available in Ruby 3.5+. The implementation converts the array-of-pairs format to maintain the exact same hash-of-arrays API that CGI.parse provided.

Changes:

  • Replaced CGI.parse with URI.decode_www_form + format conversion
  • Removed require 'cgi' statements
  • Updated documentation comments
  • No external dependencies required

This approach is more future-proof and doesn't introduce any new gem dependencies to the project. If we would rather just add it as a dependancy though, I can't roll this PR back to the original commit.

Copy link
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mmenanno Thanks!

@olleolleolle olleolleolle merged commit ce35c23 into vcr:master Aug 19, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CGI Dependancy in Ruby 3.5

2 participants