1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/irb] Check doc namespace correctly

IRB::InputCompletor::PerfectMatchedProc crashes when doc not found because a
variable name was incorrect.

https://github.com/ruby/irb/commit/889fd4928f
This commit is contained in:
aycabta 2020-02-10 23:22:24 +09:00
parent 3af3431c2c
commit 0719e1be11
2 changed files with 7 additions and 3 deletions

View file

@ -265,14 +265,14 @@ module IRB
end end
end end
PerfectMatchedProc = ->(matched) { PerfectMatchedProc = ->(matched, bind: IRB.conf[:MAIN_CONTEXT].workspace.binding) {
RDocRIDriver ||= RDoc::RI::Driver.new RDocRIDriver ||= RDoc::RI::Driver.new
if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER'] if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
IRB.send(:easter_egg) IRB.send(:easter_egg)
return return
end end
namespace = retrieve_completion_data(matched, doc_namespace: true) namespace = retrieve_completion_data(matched, bind: bind, doc_namespace: true)
return unless matched return unless namespace
if namespace.is_a?(Array) if namespace.is_a?(Array)
out = RDoc::Markup::Document.new out = RDoc::Markup::Document.new
namespace.each do |m| namespace.each do |m|

View file

@ -31,5 +31,9 @@ module TestIRB
assert_include(IRB::InputCompletor.retrieve_completion_data(":a", bind: binding), ":aiueo") assert_include(IRB::InputCompletor.retrieve_completion_data(":a", bind: binding), ":aiueo")
assert_empty(IRB::InputCompletor.retrieve_completion_data(":abcdefg", bind: binding)) assert_empty(IRB::InputCompletor.retrieve_completion_data(":abcdefg", bind: binding))
end end
def test_complete_symbol_failure
assert_nil(IRB::InputCompletor::PerfectMatchedProc.(":aiueo", bind: binding))
end
end end
end end