Skip to content

Commit ce624f0

Browse files
Avoid duplicate relative path prefix in bundle exec
When bundle exec resolves an explicit relative path like ./script and falls back to Kernel.exec, Bundler currently prepends another ./ because the resolved path is not absolute. That turns ./script into ././script, which leaks into the executed process as an unexpectedly modified argv[0]. Only prepend ./ for non-absolute paths that do not already begin with a relative path marker. This preserves the existing behavior for bare executables found in the current directory while leaving explicit relative paths unchanged. Add a regression spec that disables exec-load so the Kernel.exec path is exercised and verifies that ./script remains ./script. Closes #8930
1 parent f22056b commit ce624f0

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

bundler/lib/bundler/cli/exec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def run
2323
bin_path.delete_suffix!(".bat") if Gem.win_platform?
2424
kernel_load(bin_path, *args)
2525
else
26-
bin_path = "./" + bin_path unless File.absolute_path?(bin_path)
26+
bin_path = "./" + bin_path unless File.absolute_path?(bin_path) || bin_path.start_with?(".")
2727
kernel_exec(bin_path, *args)
2828
end
2929
else

spec/commands/exec_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,19 @@
341341
expect(out).to include(rubylib)
342342
end
343343

344+
it "does not duplicate a relative path prefix when exec'ing to a relative path" do
345+
skip "https://github.com/ruby/rubygems/issues/3351" if Gem.win_platform?
346+
347+
create_file("script", "#!/usr/bin/env ruby\nputs $0")
348+
349+
install_gemfile <<-G
350+
source "https://gem.repo1"
351+
G
352+
353+
bundle "exec ./script", env: { "BUNDLE_DISABLE_EXEC_LOAD" => "true" }
354+
expect(out).to eq("./script")
355+
end
356+
344357
it "errors nicely when the argument doesn't exist" do
345358
install_gemfile <<-G
346359
source "https://gem.repo1"

0 commit comments

Comments
 (0)