8000 Check doc namespace correctly · ruby/irb@889fd49 · GitHub
[go: up one dir, main page]

Skip to content

Commit 889fd49

Browse files
committed
Check doc namespace correctly
IRB::InputCompletor::PerfectMatchedProc crashes when doc not found because a variable name was incorrect.
1 parent dbbf086 commit 889fd49

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/irb/completion.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ def self.retrieve_completion_data(input, bind: IRB.conf[:MAIN_CONTEXT].workspace
265265
end
266266
end
267267

268-
PerfectMatchedProc = ->(matched) {
268+
PerfectMatchedProc = ->(matched, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding) {
269269
RDocRIDriver ||= RDoc::RI::Driver.new
270270
if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
271271
IRB.send(:easter_egg)
272272
return
273273
end
274-
namespace = retrieve_completion_data(matched, doc_namespace: true)
275-
return unless matched
274+
namespace = retrieve_completion_data(matched, bind: bind, doc_namespace: true)
275+
return unless namespace
276276
if namespace.is_a?(Array)
277277
out = RDoc::Markup::Document.new
278278
namespace.each do |m|

test/irb/test_completion.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ def test_complete_symbol
3131
assert_include(IRB::InputCompletor.retrieve_completion_data(":a", bind: binding), ":aiueo")
3232
assert_empty(IRB::InputCompletor.retrieve_completion_data(":abcdefg", bind: binding))
3333
end
34+
35+
def test_complete_symbol_failure
36+
assert_nil(IRB::InputCompletor::PerfectMatchedProc.(":aiueo", bind: binding))
37+
end
3438
end
3539
end

0 commit comments

Comments
 (0)
0