diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb index 64e387d49c9f27..a143d1b3e112e1 100644 --- a/lib/irb/completion.rb +++ b/lib/irb/completion.rb @@ -218,7 +218,7 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace else sym = $1 candidates = Symbol.all_symbols.collect do |s| - ":" + s.id2name.encode(Encoding.default_external) + s.inspect rescue EncodingError # ignore end diff --git a/test/irb/test_completion.rb b/test/irb/test_completion.rb index 6a24f0f9bab496..8cd14fed52b351 100644 --- a/test/irb/test_completion.rb +++ b/test/irb/test_completion.rb @@ -289,12 +289,14 @@ def has_rdoc_content? end def test_complete_symbol - %w"UTF-16LE UTF-7".each do |enc| + symbols = %w"UTF-16LE UTF-7".map do |enc| "K".force_encoding(enc).to_sym rescue end - _ = :aiueo - assert_include(IRB::InputCompletor.retrieve_completion_data(":a", bind: binding), ":aiueo") + symbols += [:aiueo, :"aiu eo"] + candidates = IRB::InputCompletor.retrieve_completion_data(":a", bind: binding) + assert_include(candidates, ":aiueo") + assert_not_include(candidates, ":aiu eo") assert_empty(IRB::InputCompletor.retrieve_completion_data(":irb_unknown_symbol_abcdefg", bind: binding)) # Do not complete empty symbol for performance reason assert_empty(IRB::InputCompletor.retrieve_completion_data(":", bind: binding))