Skip to content

Commit f546a86

Browse files
authored
Only load from cgi what is required for Ruby 3.5 (#1616)
# Description In Ruby 3.5 most of the cgi gem will be removed. Only the various escape/unescape methods will be retained by default. But: * On Ruby 3.5, `cgi/escape` is enough * Earlier versions need `cgi/util` since the unescape methods don't work otherwise. I tested this down to Ruby 2.0. https://bugs.ruby-lang.org/issues/21258 # Completed Tasks - [x] I have read the [Contributing Guide][contrib]. - [x] The pull request is complete (implemented / written). - [x] Git commits have been cleaned up (squash WIP / revert commits). - [ ] I wrote tests and ran `bundle exec rake` locally (if code is attached to PR). [contrib]: https://github.com/lsegal/yard/blob/main/CONTRIBUTING.md
2 parents 3f82376 + 745f17d commit f546a86

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

lib/yard/templates/helpers/html_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# frozen_string_literal: true
2-
require 'cgi'
2+
if RUBY_VERSION < '3.5'
3+
require 'cgi/util'
4+
else
5+
require 'cgi/escape'
6+
end
37

48
module YARD
59
module Templates::Helpers

spec/spec_helper.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ def docspec(objname = self.class.description, klass = self.class.described_type)
103103
end
104104

105105
module Kernel
106-
require 'cgi'
106+
if RUBY_VERSION < '3.5'
107+
require 'cgi/util'
108+
else
109+
require 'cgi/escape'
110+
end
107111

108112
def p(*args)
109113
puts args.map {|arg| CGI.escapeHTML(arg.inspect) }.join("<br/>\n")

0 commit comments

Comments
 (0)