Skip to content

Commit

Permalink
Avoid loading files' local variables [Bug #17623]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Mar 18, 2021
1 parent 7f75269 commit b12f0cb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
require "bundler/setup"
require_relative "../lib/irb"

IRB::TOPLEVEL_BINDING = binding
IRB.start(__FILE__)
1 change: 1 addition & 0 deletions exe/irb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

require "irb"

IRB::TOPLEVEL_BINDING = binding
IRB.start(__FILE__)
2 changes: 2 additions & 0 deletions lib/irb/workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def initialize(*main)
__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
Expand Down
10 changes: 10 additions & 0 deletions test/irb/test_workspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ def test_code_around_binding_on_irb
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
Expand Down

0 comments on commit b12f0cb

Please sign in to comment.