Replace usage of cgi for ruby 3.5 compatibility#2131
Merged
tancnle merged 1 commit intorouge-ruby:masterfrom Aug 18, 2025
Merged
Replace usage of cgi for ruby 3.5 compatibility#2131tancnle merged 1 commit intorouge-ruby:masterfrom
cgi for ruby 3.5 compatibility#2131tancnle merged 1 commit intorouge-ruby:masterfrom
Conversation
In Ruby 3.5, most of the cgi gem is removed. That includes `CGI.parse`, which `rouge` uses. But, we can subsistute it with `URI.decode_www_form`. The data is returned in a slightly different format (array of arrays instead of a hash), so do some processing to get back into the expected structure. https://bugs.ruby-lang.org/issues/21258
javierjulio
added a commit
to javierjulio/envied
that referenced
this pull request
Jun 6, 2025
In Ruby 3.5, most of the cgi gem is removed which includes `CGI.parse`. We can replace this with `URI.decode_www_form` but it has some slight differences. Seems any blank value now always comes back as nil rather nil or an empty string depending so this can be a breaking change. rouge-ruby/rouge#2131
javierjulio
added a commit
to javierjulio/envied
that referenced
this pull request
Jun 6, 2025
* Replace CGI with URI for Ruby 3.5 support In Ruby 3.5, most of the cgi gem is removed which includes `CGI.parse`. We can replace this with `URI.decode_www_form` but it has some slight differences. Seems any blank value now always comes back as nil rather nil or an empty string depending so this can be a breaking change. rouge-ruby/rouge#2131 * Update CHANGELOG.md
|
It would be great if someone could review this pull request because Rails CI started failing https://buildkite.com/rails/rails-nightly/builds/2679#0198a53d-2b95-4767-95aa-e54f1297493d/1193-1197 and this should resolve it. |
yahonda
added a commit
to yahonda/rails
that referenced
this pull request
Aug 14, 2025
This commit addresses this Rails CI Nightly failure below. https://buildkite.com/rails/rails-nightly/builds/2679#0198a53d-2b95-4767-95aa-e54f1297493d/1193-1197 - Errors addressed by this commit ``` $ ruby -v ruby 3.5.0dev (2025-08-12T14:43:46Z master c5c894c6e4) +PRISM [x86_64-linux] $ cd guides $ bundle install $ bundle exec rake guides:lint ... snip ... Generating active_record_validations.md as active_record_validations.html Generating 5_1_release_notes.md as 5_1_release_notes.html Generating asset_pipeline.md as asset_pipeline.html /home/yahonda/.local/share/mise/installs/ruby/trunk/lib/ruby/gems/3.5.0+2/gems/rouge-4.5.1/lib/rouge/lexer.rb:55:in 'Rouge::Lexer.lookup_fancy': undefined method 'parse' for class CGI (NoMethodError) opts = CGI.parse(opts || '').map do |k, vals| ^^^^^^ from /home/yahonda/.local/share/mise/installs/ruby/trunk/lib/ruby/gems/3.5.0+2/gems/rouge-4.5.1/lib/rouge/lexer.rb:95:in 'Rouge::Lexer.find_fancy' from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/markdown/renderer.rb:35:in 'RailsGuides::Markdown::Renderer#block_code' from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/markdown.rb:90:in 'Redcarpet::Markdown#render' from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/markdown.rb:90:in 'RailsGuides::Markdown#generate_body' from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/markdown.rb:28:in 'RailsGuides::Markdown#render' from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:214:in 'RailsGuides::Generator#generate_guide' from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:108:in 'block in RailsGuides::Generator#generate_guides' from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:106:in 'Array#each' from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:106:in 'RailsGuides::Generator#generate_guides' from /home/yahonda/src/github.com/rails/rails/guides/rails_guides/generator.rb:52:in 'RailsGuides::Generator#generate' from rails_guides.rb:31:in '<main>' rake aborted! Command failed with status (1): [/home/yahonda/.local/share/mise/installs/ruby/trunk/bin/ruby -Eutf-8:utf-8 rails_guides.rb] /home/yahonda/src/github.com/rails/rails/guides/Rakefile:33:in 'block (3 levels) in <top (required)>' /home/yahonda/.local/share/mise/installs/ruby/trunk/bin/bundle:25:in '<main>' Tasks: TOP => guides:lint => guides:lint:check_links (See full trace by running task with --trace) $ ``` This workaround commit can be reverted when newer version of rouge gem is relased including rouge-ruby/rouge#2131 - Ruby 3.5 removes cgi by default https://bugs.ruby-lang.org/issues/21258 ruby/ruby#13275
4 tasks
Member
|
@tancnle if gitlab doesn't currently have the capacity to maintain this gem, I should mention I am open for contracting work and am happy to put in some hours to get it back on track. |
Collaborator
|
The MR LGTM! We would need to add ruby-head to our CI at some point. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Ruby 3.5, most of the cgi gem is removed. That includes
CGI.parse, whichrougeuses.But, we can subsistute it with
URI.decode_www_form. The data is returned in a slightly different format (array of arrays instead of a hash), so do some processing to get back into the expected structure.https://bugs.ruby-lang.org/issues/21258