-
Notifications
You must be signed in to change notification settings - Fork 791
Replace usage of cgi for ruby 3.5 compatibility
#2131
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
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
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
* 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. |
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
|
@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. |
|
The MR LGTM! We would need to add ruby-head to our CI at some point. |
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