[前][次][番号順一覧][スレッド一覧]

ruby-changes:46461

From: nobu <ko1@a...>
Date: Sat, 6 May 2017 10:33:10 +0900 (JST)
Subject: [ruby-changes:46461] nobu:r58576 (trunk): share `@@accept_charset`

nobu	2017-05-06 10:33:04 +0900 (Sat, 06 May 2017)

  New Revision: 58576

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58576

  Log:
    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]

  Modified files:
    trunk/lib/cgi/core.rb
    trunk/lib/cgi/util.rb
    trunk/test/cgi/test_cgi_util.rb
Index: lib/cgi/util.rb
===================================================================
--- lib/cgi/util.rb	(revision 58575)
+++ lib/cgi/util.rb	(revision 58576)
@@ -1,5 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/lib/cgi/util.rb#L1
 # 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
   @@accept_charset="UTF-8" unless defined?(@@accept_charset)
   # URL-encode a string.
Index: lib/cgi/core.rb
===================================================================
--- lib/cgi/core.rb	(revision 58575)
+++ lib/cgi/core.rb	(revision 58576)
@@ -4,6 +4,13 @@ https://github.com/ruby/ruby/blob/trunk/lib/cgi/core.rb#L4
 # generating HTTP responses.
 #++
 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
 
@@ -734,7 +741,7 @@ class CGI https://github.com/ruby/ruby/blob/trunk/lib/cgi/core.rb#L741
   #
   #   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.
   def self.accept_charset
Index: test/cgi/test_cgi_util.rb
===================================================================
--- test/cgi/test_cgi_util.rb	(revision 58575)
+++ test/cgi/test_cgi_util.rb	(revision 58576)
@@ -60,6 +60,10 @@ class CGIUtilTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_util.rb#L60
     return unless defined?(::Encoding)
 
     assert_raise(TypeError) {CGI.unescape('', nil)}
+    assert_separately(%w[-rcgi/util], "#{<<-"begin;"}\n#{<<-"end;"}")
+    begin;
+      assert_equal("", CGI.unescape(''))
+    end;
   end
 
   def test_cgi_pretty

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]