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

ruby-changes:45428

From: nobu <ko1@a...>
Date: Thu, 2 Feb 2017 17:02:44 +0900 (JST)
Subject: [ruby-changes:45428] nobu:r57501 (trunk): escape.c: check argument

nobu	2017-02-02 17:02:36 +0900 (Thu, 02 Feb 2017)

  New Revision: 57501

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

  Log:
    escape.c: check argument
    
    * ext/cgi/escape/escape.c (optimized_unescape): check
      accept_charset encoding argument.

  Modified files:
    trunk/ext/cgi/escape/escape.c
    trunk/test/cgi/test_cgi_util.rb
Index: ext/cgi/escape/escape.c
===================================================================
--- ext/cgi/escape/escape.c	(revision 57500)
+++ ext/cgi/escape/escape.c	(revision 57501)
@@ -252,7 +252,8 @@ optimized_unescape(VALUE str, VALUE enco https://github.com/ruby/ruby/blob/trunk/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: test/cgi/test_cgi_util.rb
===================================================================
--- test/cgi/test_cgi_util.rb	(revision 57500)
+++ test/cgi/test_cgi_util.rb	(revision 57501)
@@ -56,6 +56,12 @@ class CGIUtilTest < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/cgi/test_cgi_util.rb#L56
     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("<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"))

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

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