summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomoya ishida <[email protected]>2023-06-13 19:46:34 +0900
committergit <[email protected]>2023-06-13 10:46:38 +0000
commit5d91be7c1fe10ef52cd6075328b8c121fb5420c8 (patch)
tree50eeabf92aa7bd65411cfb68b0b9a887b1a774c5
parent27b07776c99dfb4a8a4e6885462786c03e9b0660 (diff)
[ruby/irb] Use symbol.inspect instead of ":"+symbol.id2name to avoid
completion candidates including newline characters (https://github.com/ruby/irb/pull/539) https://github.com/ruby/irb/commit/aaf0c46645
-rw-r--r--lib/irb/completion.rb2
-rw-r--r--test/irb/test_completion.rb8
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index 64e387d49c..a143d1b3e1 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -218,7 +218,7 @@ module IRB
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 6a24f0f9ba..8cd14fed52 100644
--- a/test/irb/test_completion.rb
+++ b/test/irb/test_completion.rb
@@ -289,12 +289,14 @@ module TestIRB
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))