From f5829e293583aa6ba6a1f1314ee22881d58a5f96 Mon Sep 17 00:00:00 2001 From: ima1zumi Date: Wed, 17 Nov 2021 00:58:43 +0900 Subject: [ruby/reline] Correct padding space calculation fix https://github.com/ruby/irb/issues/308 This bug occurred when `dialog.width - calculate_width(s, true)` was negative. When `dialog.width` is shorter than `old_dialog.width`, it calculates how much padding it has to do. However, there are cases where `s` is longer than `dialog.width`, as in the issue. In that case, `padding_space_with_escape_sequences` will crash. Here, `old_dialog.width` is longer than `dialog.width`, so I changed the padding width to `old_dialog.width - dialog.width`. https://github.com/ruby/reline/commit/c581c31e0f --- lib/reline/line_editor.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index f6facc9da8..50bd22b424 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -858,7 +858,8 @@ class Reline::LineEditor s = ' ' * width else s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column + dialog.width, width) - s = padding_space_with_escape_sequences(s, dialog.width) + rerender_width = old_dialog.width - dialog.width + s = padding_space_with_escape_sequences(s, rerender_width) end Reline::IOGate.move_cursor_column(dialog.column + dialog.width) @output.write "\e[0m#{s}\e[0m" -- cgit v1.2.3