[ruby/irb] Avoid loading files' local variables [Bug #17623]

https://github.com/ruby/irb/commit/b12f0cb8e2
This commit is contained in:
Marc-Andre Lafortune 2021-03-18 09:44:42 -04:00 коммит произвёл aycabta
Родитель 192147afd8
Коммит 3503c94af5
3 изменённых файлов: 13 добавлений и 0 удалений

Просмотреть файл

@ -57,6 +57,8 @@ EOF
__FILE__,
__LINE__ - 3)
when 4 # binding is a copy of TOPLEVEL_BINDING (default)
# Note that this will typically be IRB::TOPLEVEL_BINDING (see exe/irb)
# This is to avoid RubyGems' local variables (see issue #17623)
@binding = TOPLEVEL_BINDING.dup
end
end

Просмотреть файл

@ -8,4 +8,5 @@
require "irb"
IRB::TOPLEVEL_BINDING = binding
IRB.start(__FILE__)

Просмотреть файл

@ -80,6 +80,16 @@ module TestIRB
assert_equal(nil, workspace.code_around_binding)
end
def test_toplevel_binding_local_variables
bug17623 = '[ruby-core:102468]'
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
status = assert_in_out_err(bundle_exec + ['-W0', '-e', <<~RUBY , '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623)
version = 'xyz' # typical rubygems loading file
load('./exe/irb')
RUBY
end
private
def with_script_lines