ruby-changes:64793
From: aycabta <ko1@a...>
Date: Fri, 8 Jan 2021 13:38:44 +0900 (JST)
Subject: [ruby-changes:64793] 88af5085db (master): [ruby/reline] Suppress crashing when auto_indent_proc returns broken indent info
https://git.ruby-lang.org/ruby.git/commit/?id=88af5085db From 88af5085dbf61dcd815e66aa9fe96c7d612c9747 Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Tue, 5 Jan 2021 18:22:00 +0900 Subject: [ruby/reline] Suppress crashing when auto_indent_proc returns broken indent info Co-authored-by: Juanito Fatas <me@j...> https://github.com/ruby/reline/commit/7c24276275 diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 10c94db..bf27328 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1131,6 +1131,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1131 new_lines = whole_lines end new_indent = @auto_indent_proc.(new_lines, @line_index, @byte_pointer, @check_new_auto_indent) + new_indent = @cursor_max if new_indent&.> @cursor_max if new_indent&.>= 0 md = new_lines[@line_index].match(/\A */) prev_indent = md[0].count(' ') diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 7950b56..ce8c4ce 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -637,6 +637,20 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L637 EOC end + def test_suppress_auto_indent_just_after_pasted + start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl --auto-indent}, startup_message: 'Multiline REPL.') + write("def hoge\n [[\n 3]]\ned") + write("\C-bn") + close + assert_screen(<<~EOC) + Multiline REPL. + prompt> def hoge + prompt> [[ + prompt> 3]] + prompt> end + EOC + end + private def write_inputrc(content) File.open(@inputrc_file, 'w') do |f| f.write content -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/