Skip to content

Conversation

@Earlopain
Copy link
Contributor

cgi/util will warn on Ruby 3.5. cgi/escape is available since Ruby 2.4, but to use CGI.unescape* methods on Ruby 3.4 and earlier, cgi/util must still be required.

There's only one place in rdoc that uses such a method, so only one place needs to handle earlier rubies.

https://bugs.ruby-lang.org/issues/21258

`cgi/util` will warn on Ruby 3.5. `cgi/escape` is available since Ruby 2.4,
but to use CGI.unescape* methods on Ruby 3.4 and earlier, `cgi/util` must still be required.

There's only one place in rdoc that uses such a method, so only one place needs to handle earlier rubies.

https://bugs.ruby-lang.org/issues/21258
require 'cgi/util'
require 'cgi/escape'
# For CGI.unescape on earlier rubies
require 'cgi/util' if RUBY_VERSION < '3.5'
Copy link
Member

Choose a reason for hiding this comment

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

ruby -rcgi/escape -e "CGI.unescape ''"
# Ruby 3.5: OK
# Ruby 3.4: uninitialized class variable @@accept_charset in #<Class:CGI> (NameError)
ruby -rcgi/escape -rcgi/util -e "CGI.unescape ''"
# Ruby 3.4: OK

Copy link
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

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

Thank you 👍

@tompng tompng merged commit 61a2dae into ruby:master May 13, 2025
25 of 30 checks passed
@tompng tompng mentioned this pull request May 19, 2025
kou pushed a commit to ruby/rss that referenced this pull request Oct 15, 2025
### Background
A warning is currently emitted in CI when running with ruby-head (Ruby
3.5-dev).
This warning occurs because `CGI::Util` will be removed in Ruby 3.5.
- https://bugs.ruby-lang.org/issues/21258
- ruby/ruby#13275

```
/home/runner/.rubies/ruby-head/lib/ruby/gems/3.5.0+2/gems/rss-0.3.2/lib/rss/rss.rb:4: warning: CGI::Util is removed from Ruby 3.5. Please use cgi/escape instead for CGI.escape and CGI.unescape features.
If you are using CGI.parse, please install and use the cgi gem instead.
/home/runner/work/rss/rss/tmp/test/test-dublincore.rb:2: warning: CGI library is removed from Ruby 3.5. Please use cgi/escape instead for CGI.escape and CGI.unescape features.
If you need to use the full features of CGI library, Please install cgi gem.
```

https://github.com/ruby/rss/actions/runs/16902042489/job/47883073913#step:6:8

### Details
This Pull Request fixes the warning by replacing the use of `cgi/util`
with `cgi/escape`.
The `cgi/escape` is available since Ruby 2.3.

### Additional Information
Similar fixes have been made in other libraries, such as the rdoc gem.
- ruby/rdoc#1366
- ruby/rdoc#1378
-
ruby/net-http@d8fd39c
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