Skip to content

Avoid duplicate relative path prefix in bundle exec#9596

Open
samuel-williams-shopify wants to merge 1 commit into
ruby:masterfrom
samuel-williams-shopify:fix-bundle-exec-relative-prefix
Open

Avoid duplicate relative path prefix in bundle exec#9596
samuel-williams-shopify wants to merge 1 commit into
ruby:masterfrom
samuel-williams-shopify:fix-bundle-exec-relative-prefix

Conversation

@samuel-williams-shopify
Copy link
Copy Markdown

@samuel-williams-shopify samuel-williams-shopify commented Jun 4, 2026

What was the end-user or developer problem that led to this PR?

bundle exec ./script can currently execute the script as ././script when Bundler resolves the command to a relative path and then uses Kernel.exec. This happens because Bundler prepends ./ to every non-absolute resolved path, including paths that already explicitly start with ./.

That makes explicit relative paths look different to the executed process than the user-provided command, and it is the duplicate-prefix issue reported in #8930.

Closes #8930

What is your fix for the problem, implemented in this PR?

Keep the existing ./ prefixing behavior for bare relative executable names, but skip it when the resolved path already starts with ./ or ../. This preserves the current support for executing commands found in the current directory, including hidden filenames like .script, while avoiding ././script for explicit relative paths like ./script.

I added regression specs that disable Bundler's exec-load optimization so the Kernel.exec path is exercised. They verify that bundle exec ./script leaves $0 as ./script, and that bundle exec .script still passes ./.script.

Make sure the following tasks are checked

  • Describe the problem / feature
  • Write tests for features and bug fixes
  • Write code to solve the problem
  • Make sure you follow the current code style and write meaningful commit messages without tags

Tophatting

  • bin/rspec spec/commands/exec_spec.rb:344 spec/commands/exec_spec.rb:357 --format documentation
  • bin/rspec spec/commands/exec_spec.rb
  • git diff --check

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 ruby#8930
@samuel-williams-shopify samuel-williams-shopify force-pushed the fix-bundle-exec-relative-prefix branch from ce624f0 to e7702be Compare June 4, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't prepend ./ to bundle exec argument?

1 participant