Backport #5280
closedirb crash "begin;retry unless false; end" (plus suggested fix)
Description
If you type "begin;retry unless false; end" into irb 1.9.2, the program prints a nice long error stack (copied below) and exits.
The problem seems to be on line 100 of ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb
in the filter_backtrace function: the backtrace strings are frozen, and line 100 tries to sub! the string:
bt.sub!(/:\s*in `irb_binding'/, '')
But all it does is return the string (or nil) so it shouldn't need to sub in-place.
It looks like simply replacing that line with
bt = bt.sub(/:\s*in `irb_binding'/, '')
would fix the problem.
Here's the trace:
Hobbes-8:cptest cphoenix$ irb
ruby-1.9.2-p180 :001 > begin ; retry unless false; end
SyntaxError: (irb):1: Invalid retry
/Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:100:in sub!': can't modify frozen string (RuntimeError) from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/workspace.rb:100:in
filter_backtrace'
from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:180:in block (3 levels) in eval_input' from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:179:in
each'
from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:179:in block (2 levels) in eval_input' from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:273:in
signal_status'
from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:156:in block in eval_input' from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in
block (2 levels) in each_top_level_statement'
from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in loop' from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in
block in each_top_level_statement'
from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in catch' from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in
each_top_level_statement'
from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:155:in eval_input' from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:70:in
block in start'
from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69:in catch' from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/irb.rb:69:in
start'
from /Users/cphoenix/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `'
Hobbes-8:cptest cphoenix$
And here's the trace after my suggested fix:
Hobbes-8:cptest cphoenix$ irb
ruby-1.9.2-p180 :001 > begin ; retry unless false; end
SyntaxError: (irb):1: Invalid retry
from (irb)
ruby-1.9.2-p180 :002 >