Skip to content

Commit

Permalink
[ruby/irb] Use symbol.inspect instead of ":"+symbol.id2name to avoid
Browse files Browse the repository at this point in the history
completion candidates including newline characters
(ruby/irb#539)

ruby/irb@aaf0c46645
  • Loading branch information
tompng authored and matzbot committed Jun 13, 2023
1 parent 27b0777 commit 5d91be7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/irb/completion.rb
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions test/irb/test_completion.rb
Expand Up @@ -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))
Expand Down

0 comments on commit 5d91be7

Please sign in to comment.