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

ruby-changes:54297

From: nobu <ko1@a...>
Date: Sun, 23 Dec 2018 14:49:50 +0900 (JST)
Subject: [ruby-changes:54297] nobu:r66506 (trunk): Restrict cause to an exception object [Bug #15447]

nobu	2018-12-23 14:49:43 +0900 (Sun, 23 Dec 2018)

  New Revision: 66506

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

  Log:
    Restrict cause to an exception object [Bug #15447]

  Modified files:
    trunk/eval.c
    trunk/test/ruby/test_exception.rb
Index: test/ruby/test_exception.rb
===================================================================
--- test/ruby/test_exception.rb	(revision 66505)
+++ test/ruby/test_exception.rb	(revision 66506)
@@ -808,7 +808,7 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L808
     e = assert_raise(exc, bug) {raise exc, "foo" => "bar", foo: "bar"}
     assert_equal({"foo" => "bar", foo: "bar"}, e.arg, bug)
 
-    e = assert_raise(exc, bug) {raise exc, "foo" => "bar", foo: "bar", cause: "zzz"}
+    e = assert_raise(exc, bug) {raise exc, "foo" => "bar", foo: "bar", cause: RuntimeError.new("zzz")}
     assert_equal({"foo" => "bar", foo: "bar"}, e.arg, bug)
 
     e = assert_raise(exc, bug) {raise exc, {}}
@@ -1346,11 +1346,9 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1346
   end
 
   def test_non_exception_cause
-    code = "#{<<~"begin;"}\n#{<<~'end;'}"
-    begin;
+    assert_raise_with_message(TypeError, /exception/) do
       raise "foo", cause: 1
     end;
-    assert_in_out_err([], code, [], /foo/, success: false, timeout: 2)
   end
 
   def test_circular_cause_handle
Index: eval.c
===================================================================
--- eval.c	(revision 66505)
+++ eval.c	(revision 66506)
@@ -509,6 +509,9 @@ exc_setup_message(const rb_execution_con https://github.com/ruby/ruby/blob/trunk/eval.c#L509
 	    *cause = get_ec_errinfo(ec);
 	}
     }
+    else if (!NIL_P(*cause) && !rb_obj_is_kind_of(*cause, rb_eException)) {
+        rb_raise(rb_eTypeError, "exception object expected");
+    }
     return mesg;
 }
 

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

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