share @@accept_charset

* lib/cgi/{core,util}.rb: include CGI::Util not only extending, to
  share `@@accept_charset` class variable, so that it is always
  accessible.  [ruby-core:80986] [Bug #13539]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-05-06 01:33:04 +00:00
parent d7f2c72322
commit 97849e1178
3 changed files with 17 additions and 2 deletions

View File

@ -4,6 +4,13 @@
# generating HTTP responses. # generating HTTP responses.
#++ #++
class CGI class CGI
unless const_defined?(:Util)
module Util
@@accept_charset = "UTF-8" # :nodoc:
end
include Util
extend Util
end
$CGI_ENV = ENV # for FCGI support $CGI_ENV = ENV # for FCGI support
@ -734,7 +741,7 @@ class CGI
# #
# CGI.accept_charset = "EUC-JP" # CGI.accept_charset = "EUC-JP"
# #
@@accept_charset="UTF-8" @@accept_charset="UTF-8" if false # needed for rdoc?
# Return the accept character set for all new CGI instances. # Return the accept character set for all new CGI instances.
def self.accept_charset def self.accept_charset

View File

@ -1,5 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
class CGI; module Util; end; extend Util; end class CGI
module Util; end
include Util
extend Util
end
module CGI::Util module CGI::Util
@@accept_charset="UTF-8" unless defined?(@@accept_charset) @@accept_charset="UTF-8" unless defined?(@@accept_charset)
# URL-encode a string. # URL-encode a string.

View File

@ -60,6 +60,10 @@ class CGIUtilTest < Test::Unit::TestCase
return unless defined?(::Encoding) return unless defined?(::Encoding)
assert_raise(TypeError) {CGI.unescape('', nil)} assert_raise(TypeError) {CGI.unescape('', nil)}
assert_separately(%w[-rcgi/util], "#{<<-"begin;"}\n#{<<-"end;"}")
begin;
assert_equal("", CGI.unescape(''))
end;
end end
def test_cgi_pretty def test_cgi_pretty