ruby-changes:47395
From: nagachika <ko1@a...>
Date: Sat, 5 Aug 2017 10:53:49 +0900 (JST)
Subject: [ruby-changes:47395] nagachika:r59511 (ruby_2_4): merge revision(s) 57501, 58576: [Backport #13539]
nagachika 2017-08-05 10:53:44 +0900 (Sat, 05 Aug 2017) New Revision: 59511 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59511 Log: merge revision(s) 57501,58576: [Backport #13539] escape.c: check argument * ext/cgi/escape/escape.c (optimized_unescape): check accept_charset encoding argument. 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 directories: branches/ruby_2_4/ Modified files: branches/ruby_2_4/ext/cgi/escape/escape.c branches/ruby_2_4/lib/cgi/core.rb branches/ruby_2_4/lib/cgi/util.rb branches/ruby_2_4/test/cgi/test_cgi_util.rb branches/ruby_2_4/version.h Index: ruby_2_4/lib/cgi/util.rb =================================================================== --- ruby_2_4/lib/cgi/util.rb (revision 59510) +++ ruby_2_4/lib/cgi/util.rb (revision 59511) @@ -1,5 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/lib/cgi/util.rb#L1 # frozen_string_literal: false -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: ruby_2_4/lib/cgi/core.rb =================================================================== --- ruby_2_4/lib/cgi/core.rb (revision 59510) +++ ruby_2_4/lib/cgi/core.rb (revision 59511) @@ -4,6 +4,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/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/ruby_2_4/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: ruby_2_4/ext/cgi/escape/escape.c =================================================================== --- ruby_2_4/ext/cgi/escape/escape.c (revision 59510) +++ ruby_2_4/ext/cgi/escape/escape.c (revision 59511) @@ -252,7 +252,8 @@ optimized_unescape(VALUE str, VALUE enco https://github.com/ruby/ruby/blob/trunk/ruby_2_4/ext/cgi/escape/escape.c#L252 long i, len, beg = 0; VALUE dest = 0; const char *cstr; - int cr, origenc, encidx = rb_to_encoding_index(encoding); + rb_encoding *enc = rb_to_encoding(encoding); + int cr, origenc, encidx = rb_enc_to_index(enc); len = RSTRING_LEN(str); cstr = RSTRING_PTR(str); Index: ruby_2_4/version.h =================================================================== --- ruby_2_4/version.h (revision 59510) +++ ruby_2_4/version.h (revision 59511) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1 #define RUBY_VERSION "2.4.2" #define RUBY_RELEASE_DATE "2017-08-05" -#define RUBY_PATCHLEVEL 174 +#define RUBY_PATCHLEVEL 175 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 8 Index: ruby_2_4/test/cgi/test_cgi_util.rb =================================================================== --- ruby_2_4/test/cgi/test_cgi_util.rb (revision 59510) +++ ruby_2_4/test/cgi/test_cgi_util.rb (revision 59511) @@ -53,6 +53,16 @@ class CGIUtilTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/cgi/test_cgi_util.rb#L53 assert_equal(Encoding::UTF_8, CGI::unescape("%C0%3C%3C".force_encoding("UTF-8")).encoding) end + def test_cgi_unescape_accept_charset + 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 assert_equal("<HTML>\n <BODY>\n </BODY>\n</HTML>\n",CGI::pretty("<HTML><BODY></BODY></HTML>")) assert_equal("<HTML>\n\t<BODY>\n\t</BODY>\n</HTML>\n",CGI::pretty("<HTML><BODY></BODY></HTML>","\t")) Index: ruby_2_4 =================================================================== --- ruby_2_4 (revision 59510) +++ ruby_2_4 (revision 59511) Property changes on: ruby_2_4 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r57501,58576 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/