Skip to content

Commit 777e5ef

Browse files
committed
Expand path of user provided file in runner
If user provides a file without absolute or relative path and the file exists in any of the directories of the $LOAD_PATH the `Kernel.load` method will load the latter one instead of the intended one. Expanding the path of the file forces Kernel to load the correct file using its absolute path. * Fixes rails#42007
1 parent 9a263e9 commit 777e5ef

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

railties/lib/rails/commands/runner/runner_command.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ def perform(code_or_file = nil, *command_argv)
3838
if code_or_file == "-"
3939
eval($stdin.read, TOPLEVEL_BINDING, "stdin")
4040
elsif File.exist?(code_or_file)
41-
$0 = code_or_file
42-
Kernel.load code_or_file
41+
expanded_file_path = File.expand_path code_or_file
42+
$0 = expanded_file_path
43+
Kernel.load expanded_file_path
4344
else
4445
begin
4546
eval(code_or_file, TOPLEVEL_BINDING, __FILE__, __LINE__)

0 commit comments

Comments
 (0)