Skip to content

Commit 209bcf7

Browse files
authored
Fix IRB crash when typing string literal with control/meta sequence (#1182)
1 parent 2ec9603 commit 209bcf7

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

lib/irb/ruby-lex.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def should_continue?(tokens, line, line_num)
107107
t.type != :NEWLINE &&
108108
t.type != :EOF
109109
trailing = line.byteslice(t.location.end_column..)
110+
trailing ||= '' # in case end_line is wrong (e.g. `"\C-`)
110111
break
111112
end
112113
end

test/irb/test_irb.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,12 @@ def test_dynamic_prompt_with_blank_line
828828
assert_dynamic_prompt(input_with_prompt)
829829
end
830830

831+
def test_dynamic_prompt_with_incomplete_ctrl_meta_sequence_string
832+
assert_dynamic_prompt([['001:0:":* ', %q("\C-)]])
833+
assert_dynamic_prompt([['001:0:":* ', %q("\M-)]])
834+
assert_dynamic_prompt([['001:0:":* ', %q("\C-\M-)]])
835+
end
836+
831837
def assert_dynamic_prompt(input_with_prompt)
832838
expected_prompt_list, lines = input_with_prompt.transpose
833839
def @irb.generate_prompt(opens, continue, line_offset)

0 commit comments

Comments
 (0)