Skip to content

fix: replace CGI.parse, removed in Ruby 4.0, with URI.decode_www_form - #793

Merged
kishore7snehil merged 3 commits into
auth0:masterfrom
gagalago:fix/cgi-parse-ruby-4
Sep 1, 2026
Merged

fix: replace CGI.parse, removed in Ruby 4.0, with URI.decode_www_form#793
kishore7snehil merged 3 commits into
auth0:masterfrom
gagalago:fix/cgi-parse-ruby-4

Conversation

@gagalago

Copy link
Copy Markdown
Contributor

Changes

test_par_authorization_url_builds_correctly fails on Ruby 4.0 because CGI.parse no longer exists:

NoMethodError: undefined method 'parse' for class CGI
    test/unit/authentication_endpoints_test.rb:478

Ruby 4.0 trimmed the cgi library down to its escaping helpers. CGI.escape, CGI.unescape, CGI.escapeHTML and CGI.unescapeHTML all remain, but CGI.parse is gone, and require "cgi" does not bring it back.

This replaces the single call with URI.decode_www_form(...).to_h, which is the standard-library replacement and needs no new require — the test already uses URI.parse on the line above.

params = URI.decode_www_form(parsed.query).to_h

assert_equal @client_id, params["client_id"]
assert_equal request_uri, params["request_uri"]

URI.decode_www_form returns [[key, value], ...], so to_h gives values directly and the two .first calls are no longer needed. Both parameters in this test are single-valued, so nothing is lost.

No library code is affected. The only CGI usage in lib/ is CGI.escape in AuthenticationEndpoints#to_query, which still exists in Ruby 4.0. This is a test-only fix.

References

Found while testing an application against auth0 on Ruby 4.0.6. auth0.gemspec declares required_ruby_version = ">= 3.3.0" with no upper bound, so Ruby 4 is in scope for the gem, and this is currently the only thing standing between the suite and a clean run there.

Testing

No new test — this repairs an existing one, which is the check.

Full suite, same command on both interpreters:

Ruby before after
3.3.9 552 runs, 0 failures, 0 errors 552 runs, 0 failures, 0 errors
4.0.6 552 runs, 0 failures, **1 error** 552 runs, 0 failures, 0 errors

I also confirmed the replacement is equivalent for this test's input rather than assuming it. request_uri is urn:ietf:params:oauth:request_uri:the.request.uri, whose colons are percent-encoded by CGI.escape in to_query; URI.decode_www_form decodes them back identically, so the assertion still compares real decoded values and has not become vacuous.

  • This change adds unit test coverage
  • This change adds integration test coverage
  • This change has been tested on the latest version of Ruby

Checklist

@kishore7snehil

Copy link
Copy Markdown
Contributor

@gagalago Please sign the commits so that I can approve it.

@gagalago
gagalago force-pushed the fix/cgi-parse-ruby-4 branch from 780adc8 to 026d8e2 Compare August 31, 2026 11:47
@gagalago

Copy link
Copy Markdown
Contributor Author

@gagalago Please sign the commits so that I can approve it.

is it good like this?

@kishore7snehil kishore7snehil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@kishore7snehil
kishore7snehil merged commit 4bbf7b9 into auth0:master Sep 1, 2026
8 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.

2 participants