Skip to content

Commit

Permalink
Use symbol.inspect instead of ":"+symbol.id2name to avoid completion …
Browse files Browse the repository at this point in the history
…candidates including newline characters (#539)
  • Loading branch information
tompng authored Jun 13, 2023
1 parent 0506dd2 commit aaf0c46
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 aaf0c46

Please sign in to comment.