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

ruby-changes:44202

From: nobu <ko1@a...>
Date: Wed, 28 Sep 2016 00:21:11 +0900 (JST)
Subject: [ruby-changes:44202] nobu:r56274 (trunk): error.c: check argument of Warning.warn

nobu	2016-09-28 00:21:01 +0900 (Wed, 28 Sep 2016)

  New Revision: 56274

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

  Log:
    error.c: check argument of Warning.warn
    
    * error.c (rb_warning_s_warn): the argument must be an
      ASCII-compatible string.  [ruby-core:77430] [Bug #12793]

  Modified files:
    trunk/ChangeLog
    trunk/error.c
    trunk/test/ruby/test_exception.rb
Index: error.c
===================================================================
--- error.c	(revision 56273)
+++ error.c	(revision 56274)
@@ -152,6 +152,8 @@ ruby_only_for_internal_use(const char *f https://github.com/ruby/ruby/blob/trunk/error.c#L152
 static VALUE
 rb_warning_s_warn(VALUE mod, VALUE str)
 {
+    Check_Type(str, T_STRING);
+    rb_must_asciicompat(str);
     rb_write_error_str(str);
     return Qnil;
 }
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56273)
+++ ChangeLog	(revision 56274)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Sep 28 00:21:00 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* error.c (rb_warning_s_warn): the argument must be an
+	  ASCII-compatible string.  [ruby-core:77430] [Bug #12793]
+
 Tue Sep 27 23:22:31 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* parse.y (symbol, dsym, parser_set_number_literal): set state to
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 56273)
+++ test/ruby/test_exception.rb	(revision 56274)
@@ -940,4 +940,16 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L940
       remove_method :warn2
     end
   end
+
+  def test_warning_warn_invalid_argument
+    assert_raise(TypeError) do
+      ::Warning.warn nil
+    end
+    assert_raise(TypeError) do
+      ::Warning.warn 1
+    end
+    assert_raise(Encoding::CompatibilityError) do
+      ::Warning.warn "\x00a\x00b\x00c".force_encoding("utf-16be")
+    end
+  end
 end

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

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