Skip to content

Commit b12f0cb

Browse files
committed
Avoid loading files' local variables [Bug #17623]
1 parent 7f75269 commit b12f0cb

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

bin/console

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
require "bundler/setup"
44
require_relative "../lib/irb"
55

6+
IRB::TOPLEVEL_BINDING = binding
67
IRB.start(__FILE__)

exe/irb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
require "irb"
1010

11+
IRB::TOPLEVEL_BINDING = binding
1112
IRB.start(__FILE__)

lib/irb/workspace.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def initialize(*main)
5757
__FILE__,
5858
__LINE__ - 3)
5959
when 4 # binding is a copy of TOPLEVEL_BINDING (default)
60+
# Note that this will typically be IRB::TOPLEVEL_BINDING (see exe/irb)
61+
# This is to avoid RubyGems' local variables (see issue #17623)
6062
@binding = TOPLEVEL_BINDING.dup
6163
end
6264
end

test/irb/test_workspace.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ def test_code_around_binding_on_irb
8080
assert_equal(nil, workspace.code_around_binding)
8181
end
8282

83+
84+
def test_toplevel_binding_local_variables
85+
bug17623 = '[ruby-core:102468]'
86+
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
87+
status = assert_in_out_err(bundle_exec + ['-W0', '-e', <<~RUBY , '--', '-f', '--'], 'binding.local_variables', /\[:_\]/, [], bug17623)
88+
version = 'xyz' # typical rubygems loading file
89+
load('./exe/irb')
90+
RUBY
91+
end
92+
8393
private
8494

8595
def with_script_lines

0 commit comments

Comments
 (0)