[前][次][番号順一覧][スレッド一覧]

ruby-changes:67675

From: Marc-Andre <ko1@a...>
Date: Fri, 10 Sep 2021 06:37:20 +0900 (JST)
Subject: [ruby-changes:67675] 3503c94af5 (master): [ruby/irb] Avoid loading files' local variables [Bug #17623]

https://git.ruby-lang.org/ruby.git/commit/?id=3503c94af5

From 3503c94af501e38164613ef8347174a27346828a Mon Sep 17 00:00:00 2001
From: Marc-Andre Lafortune <github@m...>
Date: Thu, 18 Mar 2021 09:44:42 -0400
Subject: [ruby/irb] Avoid loading files' local variables [Bug #17623]

https://github.com/ruby/irb/commit/b12f0cb8e2
---
 lib/irb/workspace.rb       |  2 ++
 libexec/irb                |  1 +
 test/irb/test_workspace.rb | 10 ++++++++++
 3 files changed, 13 insertions(+)

diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb
index 78d434d..8157e21 100644
--- a/lib/irb/workspace.rb
+++ b/lib/irb/workspace.rb
@@ -57,6 +57,8 @@ EOF https://github.com/ruby/ruby/blob/trunk/lib/irb/workspace.rb#L57
                           __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
diff --git a/libexec/irb b/libexec/irb
index c64ee85..7cd2448 100755
--- a/libexec/irb
+++ b/libexec/irb
@@ -8,4 +8,5 @@ https://github.com/ruby/ruby/blob/trunk/libexec/irb#L8
 
 require "irb"
 
+IRB::TOPLEVEL_BINDING = binding
 IRB.start(__FILE__)
diff --git a/test/irb/test_workspace.rb b/test/irb/test_workspace.rb
index a39bea2..6165348 100644
--- a/test/irb/test_workspace.rb
+++ b/test/irb/test_workspace.rb
@@ -80,6 +80,16 @@ module TestIRB https://github.com/ruby/ruby/blob/trunk/test/irb/test_workspace.rb#L80
       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
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]