From daa592293b5a10f487cc9000863e052d2a28884f Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Fri, 22 Sep 2017 10:29:23 +0900 Subject: Use `TOPLEVEL_BINDING` in rails runner command Binding to capture the local scope. This means that if a constant with same name as constant specified by the user exists in local scope, constant defined in local will use. This is different from what the user expects. Therefore, fixed to use top-level binding instead of local scope. Fixes #30644 --- railties/lib/rails/commands/runner/runner_command.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/commands/runner/runner_command.rb b/railties/lib/rails/commands/runner/runner_command.rb index cd9462e08f..30fbf04982 100644 --- a/railties/lib/rails/commands/runner/runner_command.rb +++ b/railties/lib/rails/commands/runner/runner_command.rb @@ -32,13 +32,13 @@ module Rails ARGV.replace(command_argv) if code_or_file == "-" - eval($stdin.read, binding, "stdin") + eval($stdin.read, TOPLEVEL_BINDING, "stdin") elsif File.exist?(code_or_file) $0 = code_or_file Kernel.load code_or_file else begin - eval(code_or_file, binding, __FILE__, __LINE__) + eval(code_or_file, TOPLEVEL_BINDING, __FILE__, __LINE__) rescue SyntaxError, NameError => error $stderr.puts "Please specify a valid ruby command or the path of a script to run." $stderr.puts "Run '#{self.class.executable} -h' for help." -- cgit v1.2.3