Avoid duplicate relative path prefix in bundle exec#9596
Open
samuel-williams-shopify wants to merge 1 commit into
Open
Avoid duplicate relative path prefix in bundle exec#9596samuel-williams-shopify wants to merge 1 commit into
samuel-williams-shopify wants to merge 1 commit into
Conversation
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
ce624f0 to
e7702be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was the end-user or developer problem that led to this PR?
bundle exec ./scriptcan currently execute the script as././scriptwhen Bundler resolves the command to a relative path and then usesKernel.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././scriptfor explicit relative paths like./script.I added regression specs that disable Bundler's exec-load optimization so the
Kernel.execpath is exercised. They verify thatbundle exec ./scriptleaves$0as./script, and thatbundle exec .scriptstill passes./.script.Make sure the following tasks are checked
Tophatting
bin/rspec spec/commands/exec_spec.rb:344 spec/commands/exec_spec.rb:357 --format documentationbin/rspec spec/commands/exec_spec.rbgit diff --check