summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2019-08-08 18:38:40 -0400
committeraycabta <aycabta@gmail.com>2019-08-18 07:43:19 +0900
commite9f82585eed414ff090d9ef7b667d0f3c1561a01 (patch)
tree76e9114cd3868262f5542364610449ba2a5e463b
parent7bb0a7d7cba7bbeb03d531c13ccf73b6d4e688f6 (diff)
Don't crash when deleting at the end of the line
To reproduce this bug, type one character into irb, then press the delete key on your keyboard.
-rw-r--r--lib/reline/line_editor.rb4
-rw-r--r--test/reline/test_key_actor_emacs.rb10
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 4c97a6fed9..742ffedf9a 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -1712,8 +1712,8 @@ class Reline::LineEditor
end
private def ed_delete_next_char(key, arg: 1)
- unless @line.empty?
- byte_size = Reline::Unicode.get_next_mbchar_size(@line, @byte_pointer)
+ byte_size = Reline::Unicode.get_next_mbchar_size(@line, @byte_pointer)
+ unless @line.empty? || byte_size == 0
@line, mbchar = byteslice!(@line, @byte_pointer, byte_size)
copy_for_vi(mbchar)
width = Reline::Unicode.get_mbchar_width(mbchar)
diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb
index 7dd81caaf0..5c5e74f5c8 100644
--- a/test/reline/test_key_actor_emacs.rb
+++ b/test/reline/test_key_actor_emacs.rb
@@ -443,6 +443,16 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_line('abc')
end
+ def test_ed_delete_next_char
+ input_keys('abc')
+ assert_cursor(3)
+ assert_cursor_max(3)
+ @line_editor.input_key(Reline::Key.new(:key_delete, :key_delete, false))
+ assert_cursor(3)
+ assert_cursor_max(3)
+ assert_line('abc')
+ end
+
def test_em_next_word
assert_byte_pointer_size('')
assert_cursor(0)