diff options
| author | aycabta <aycabta@gmail.com> | 2021-09-02 04:43:36 +0900 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2021-09-02 14:07:48 +0900 |
| commit | 4852d87a81ae8b7f239787bdc18560f89dd18cab (patch) | |
| tree | ccea6e231492d2d73c9459cfa2e19c031f17041a | |
| parent | 5f23003cc204182134af2682f1de1e8801b3f423 (diff) | |
[ruby/reline] Fix a crash when completing empty line
https://github.com/ruby/reline/commit/8226ae7e57
| -rw-r--r-- | lib/reline/line_editor.rb | 4 | ||||
| -rw-r--r-- | test/reline/yamatanooroti/test_rendering.rb | 13 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 9442bdf5cc..2a1d4b4382 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -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 diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 0ea5b1a25d..7a73f07d5d 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -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 |
