diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 86fc4d9bba..a37c9d8508 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -405,7 +405,10 @@ class Reline::LineEditor private def complete_internal_proc(list, is_menu) preposing, target, postposing = @retrieve_completion_block.(@line, @byte_pointer) - list = list.select { |i| i&.start_with?(target) } + list = list.select { |i| + raise Encoding::CompatibilityError if i and i.encoding != @encoding + i&.start_with?(target) + } if is_menu menu(target, list) return nil diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index 04afff34d9..535906ea24 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -4,8 +4,9 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase def setup @prompt = '> ' @config = Reline::Config.new # Emacs mode is default + @encoding = (RELINE_TEST_ENCODING rescue Encoding.default_external) @line_editor = Reline::LineEditor.new(@config) - @line_editor.reset(@prompt, (RELINE_TEST_ENCODING rescue Encoding.default_external)) + @line_editor.reset(@prompt, @encoding) @line_editor.retrieve_completion_block = Reline.method(:retrieve_completion_block) end @@ -1054,6 +1055,8 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase foo_bar foo_baz qux + }.map { |i| + i.encode(@encoding) } } input_keys('fo') @@ -1096,6 +1099,8 @@ class Reline::KeyActor::Emacs::Test < Reline::TestCase foo_bar foo_baz qux + }.map { |i| + i.encode(@encoding) } } input_keys('abcde fo ABCDE')