Skip to content

Commit f5254a3

Browse files
authored
Fix nil error on debugger prompt (#1097)
* Fix nil error on debugger prompt * Delete unnecessary test case * Use empty string on prompt when to_s returns nil.
1 parent 3265f09 commit f5254a3

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

lib/irb.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,10 @@ def format_prompt(format, ltype, indent, line_no) # :nodoc:
612612
when "N"
613613
@context.irb_name
614614
when "m"
615-
main_str = @context.safe_method_call_on_main(:to_s) rescue "!#{$!.class}"
615+
main_str = "#{@context.safe_method_call_on_main(:to_s)}" rescue "!#{$!.class}"
616616
truncate_prompt_main(main_str)
617617
when "M"
618-
main_str = @context.safe_method_call_on_main(:inspect) rescue "!#{$!.class}"
618+
main_str = "#{@context.safe_method_call_on_main(:inspect)}" rescue "!#{$!.class}"
619619
truncate_prompt_main(main_str)
620620
when "l"
621621
ltype

test/irb/test_debugger_integration.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,31 @@ def test_debug
5151
assert_match(/=> 2\| puts "hello"/, output)
5252
end
5353

54+
def test_debug_class_to_s_return_nil
55+
write_ruby <<~'ruby'
56+
class ToSReturnsNil
57+
def to_s
58+
nil
59+
end
60+
61+
def do_something
62+
binding.irb
63+
end
64+
end
65+
66+
ToSReturnsNil.new.do_something
67+
ruby
68+
69+
output = run_ruby_file do
70+
type "debug"
71+
type "next"
72+
type "continue"
73+
end
74+
75+
assert_match(/irb\(\):001> debug/, output)
76+
assert_match(/irb:rdbg\(\):002> next/, output)
77+
end
78+
5479
def test_debug_command_only_runs_once
5580
write_ruby <<~'ruby'
5681
binding.irb

0 commit comments

Comments
 (0)