* 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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47164 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
hsbt 2014-08-13 02:19:48 +00:00
parent 087d1d2749
commit f741fd2d9d
3 changed files with 34 additions and 11 deletions

View File

@ -1,3 +1,10 @@
Wed Aug 13 11:17:00 2014 Shimpei Makimoto <github@makimoto.org>
* 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@gmail.com> Wed Aug 13 11:08:55 2014 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* lib/irb/completion.rb: fixed broken completion list with * lib/irb/completion.rb: fixed broken completion list with

View File

@ -497,7 +497,7 @@ module IRB
end end
if exc if exc
print exc.class, ": ", exc, "\n" 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) !(SyntaxError === exc)
irb_bug = true irb_bug = true
else else
@ -507,6 +507,7 @@ module IRB
messages = [] messages = []
lasts = [] lasts = []
levels = 0 levels = 0
if exc.backtrace
for m in exc.backtrace for m in exc.backtrace
m = @context.workspace.filter_backtrace(m) unless irb_bug m = @context.workspace.filter_backtrace(m) unless irb_bug
if m if m
@ -521,6 +522,7 @@ module IRB
end end
end end
end end
end
print messages.join("\n"), "\n" print messages.join("\n"), "\n"
unless lasts.empty? unless lasts.empty?
printf "... %d levels...\n", levels if levels > 0 printf "... %d levels...\n", levels if levels > 0

View File

@ -0,0 +1,14 @@
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