summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/reline/line_editor.rb2
-rw-r--r--test/reline/test_key_actor_emacs.rb45
2 files changed, 46 insertions, 1 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 928b043669..5d23c82ded 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -553,7 +553,7 @@ class Reline::LineEditor
raise Encoding::CompatibilityError, "#{target.encoding.name} is not comaptible with #{i.encoding.name}"
end
if @config.completion_ignore_case
- i&.downcase.start_with?(target.downcase)
+ i&.downcase&.start_with?(target.downcase)
else
i&.start_with?(target)
end
diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb
index cd5b926afe..4e3184bd3f 100644
--- a/test/reline/test_key_actor_emacs.rb
+++ b/test/reline/test_key_actor_emacs.rb
@@ -1363,6 +1363,51 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase
assert_line('abcde foo_o_ ABCDE')
end
+ def test_completion_with_nil_value
+ @line_editor.completion_proc = proc { |word|
+ %w{
+ foo_foo
+ foo_bar
+ Foo_baz
+ qux
+ }.map { |i|
+ i.encode(@encoding)
+ }.prepend(nil)
+ }
+ @config.completion_ignore_case = true
+ input_keys('fo')
+ assert_byte_pointer_size('fo')
+ assert_cursor(2)
+ assert_cursor_max(2)
+ assert_line('fo')
+ assert_equal(nil, @line_editor.instance_variable_get(:@menu_info))
+ input_keys("\C-i", false)
+ assert_byte_pointer_size('foo_')
+ assert_cursor(4)
+ assert_cursor_max(4)
+ assert_line('foo_')
+ assert_equal(nil, @line_editor.instance_variable_get(:@menu_info))
+ input_keys("\C-i", false)
+ assert_byte_pointer_size('foo_')
+ assert_cursor(4)
+ assert_cursor_max(4)
+ assert_line('foo_')
+ assert_equal(%w{foo_foo foo_bar Foo_baz}, @line_editor.instance_variable_get(:@menu_info).list)
+ input_keys('a')
+ input_keys("\C-i", false)
+ assert_byte_pointer_size('foo_a')
+ assert_cursor(5)
+ assert_cursor_max(5)
+ assert_line('foo_a')
+ input_keys("\C-h", false)
+ input_keys('b')
+ input_keys("\C-i", false)
+ assert_byte_pointer_size('foo_ba')
+ assert_cursor(6)
+ assert_cursor_max(6)
+ assert_line('foo_ba')
+ end
+
def test_em_kill_region
input_keys('abc def{bbb}ccc ddd ')
assert_byte_pointer_size('abc def{bbb}ccc ddd ')