1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/reline] Fix a crash when completing empty line

https://github.com/ruby/reline/commit/8226ae7e57
This commit is contained in:
aycabta 2021-09-02 04:43:36 +09:00 committed by git
parent 5f23003cc2
commit 4852d87a81
2 changed files with 16 additions and 1 deletions

View file

@ -1295,8 +1295,10 @@ class Reline::LineEditor
end
end
completed = @completion_journey_data.list[@completion_journey_data.pointer]
@line = (@completion_journey_data.preposing + completed + @completion_journey_data.postposing).split("\n")[@line_index]
new_line = (@completion_journey_data.preposing + completed + @completion_journey_data.postposing).split("\n")[@line_index]
@line = new_line.nil? ? String.new(encoding: @encoding) : new_line
line_to_pointer = (@completion_journey_data.preposing + completed).split("\n").last
line_to_pointer = String.new(encoding: @encoding) if line_to_pointer.nil?
@cursor_max = calculate_width(@line)
@cursor = calculate_width(line_to_pointer)
@byte_pointer = line_to_pointer.bytesize

View file

@ -823,6 +823,19 @@ begin
EOC
end
def test_completion_journey_with_empty_line
write_inputrc <<~LINES
set editing-mode vi
LINES
start_terminal(10, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --complete}, startup_message: 'Multiline REPL.')
write("\C-n\C-p")
close
assert_screen(<<~'EOC')
Multiline REPL.
prompt>
EOC
end
def write_inputrc(content)
File.open(@inputrc_file, 'w') do |f|
f.write content