diff options
-rw-r--r-- | ext/cgi/escape/escape.c | 3 | ||||
-rw-r--r-- | lib/cgi/core.rb | 9 | ||||
-rw-r--r-- | lib/cgi/util.rb | 6 | ||||
-rw-r--r-- | test/cgi/test_cgi_util.rb | 10 | ||||
-rw-r--r-- | version.h | 2 |
5 files changed, 26 insertions, 4 deletions
diff --git a/ext/cgi/escape/escape.c b/ext/cgi/escape/escape.c index 7289f43b8d..fa3d6c2038 100644 --- a/ext/cgi/escape/escape.c +++ b/ext/cgi/escape/escape.c @@ -252,7 +252,8 @@ optimized_unescape(VALUE str, VALUE encoding) 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); diff --git a/lib/cgi/core.rb b/lib/cgi/core.rb index 1a741dcd76..e5de7db5e9 100644 --- a/lib/cgi/core.rb +++ b/lib/cgi/core.rb @@ -4,6 +4,13 @@ # 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 # # 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 diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb index 66fa54d8e9..2bf46055e2 100644 --- a/lib/cgi/util.rb +++ b/lib/cgi/util.rb @@ -1,5 +1,9 @@ # 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. diff --git a/test/cgi/test_cgi_util.rb b/test/cgi/test_cgi_util.rb index 4e4f7a45e7..4ac9be86bf 100644 --- a/test/cgi/test_cgi_util.rb +++ b/test/cgi/test_cgi_util.rb @@ -53,6 +53,16 @@ class CGIUtilTest < Test::Unit::TestCase 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")) @@ -1,6 +1,6 @@ #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 |