From c373866444f9f2ad35467ed262e5455679824e48 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 2 Feb 2017 08:02:36 +0000 Subject: [PATCH] escape.c: check argument * ext/cgi/escape/escape.c (optimized_unescape): check accept_charset encoding argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/cgi/escape/escape.c | 3 ++- test/cgi/test_cgi_util.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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/test/cgi/test_cgi_util.rb b/test/cgi/test_cgi_util.rb index 9957301191..0765249c4e 100644 --- a/test/cgi/test_cgi_util.rb +++ b/test/cgi/test_cgi_util.rb @@ -56,6 +56,12 @@ 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)} + end + def test_cgi_pretty assert_equal("\n \n \n\n",CGI::pretty("")) assert_equal("\n\t\n\t\n\n",CGI::pretty("","\t"))