ruby-changes:35082
From: hsbt <ko1@a...>
Date: Wed, 13 Aug 2014 11:19:56 +0900 (JST)
Subject: [ruby-changes:35082] hsbt:r47164 (trunk): * lib/irb.rb: Prevent irb from crashing when exception with
hsbt 2014-08-13 11:19:48 +0900 (Wed, 13 Aug 2014) New Revision: 47164 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47164 Log: * lib/irb.rb: Prevent irb from crashing when exception with nil backtrace is raised. [fix GH-434][ruby-core:58078][Bug #9063] * test/irb/test_raise_no_backtrace_exception.rb: ditto. Added files: trunk/test/irb/test_raise_no_backtrace_exception.rb Modified files: trunk/ChangeLog trunk/lib/irb.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 47163) +++ ChangeLog (revision 47164) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Aug 13 11:17:00 2014 Shimpei Makimoto <github@m...> + + * lib/irb.rb: Prevent irb from crashing when exception with + nil backtrace is raised. + [fix GH-434][ruby-core:58078][Bug #9063] + * test/irb/test_raise_no_backtrace_exception.rb: ditto. + Wed Aug 13 11:08:55 2014 SHIBATA Hiroshi <shibata.hiroshi@g...> * lib/irb/completion.rb: fixed broken completion list with Index: lib/irb.rb =================================================================== --- lib/irb.rb (revision 47163) +++ lib/irb.rb (revision 47164) @@ -497,7 +497,7 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L497 end if exc print exc.class, ": ", exc, "\n" - if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ && + if exc.backtrace && exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ && !(SyntaxError === exc) irb_bug = true else @@ -507,16 +507,18 @@ module IRB https://github.com/ruby/ruby/blob/trunk/lib/irb.rb#L507 messages = [] lasts = [] levels = 0 - for m in exc.backtrace - m = @context.workspace.filter_backtrace(m) unless irb_bug - if m - if messages.size < @context.back_trace_limit - messages.push "\tfrom "+m - else - lasts.push "\tfrom "+m - if lasts.size > @context.back_trace_limit - lasts.shift - levels += 1 + if exc.backtrace + for m in exc.backtrace + m = @context.workspace.filter_backtrace(m) unless irb_bug + if m + if messages.size < @context.back_trace_limit + messages.push "\tfrom "+m + else + lasts.push "\tfrom "+m + if lasts.size > @context.back_trace_limit + lasts.shift + levels += 1 + end end end end Index: test/irb/test_raise_no_backtrace_exception.rb =================================================================== --- test/irb/test_raise_no_backtrace_exception.rb (revision 0) +++ test/irb/test_raise_no_backtrace_exception.rb (revision 47164) @@ -0,0 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/test/irb/test_raise_no_backtrace_exception.rb#L1 +require 'test/unit' +require_relative '../ruby/envutil' + +module TestIRB + class TestRaiseNoBacktraceException < Test::Unit::TestCase + def test_raise_exception + status = assert_in_out_err(%w[-rirb -e IRB.start(__FILE__) -- -f --], <<-IRB, /Exception: foo/, []) + e = Exception.new("foo") + def e.backtrace; nil; end + raise e +IRB + end + end +end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/