Avoid space-containing absolute path in RUBYOPT#9696
Open
hsbt wants to merge 2 commits into
Open
Conversation
RUBYOPT is split on whitespace with no quoting mechanism, so the absolute `-r` path injected by set_rubyopt tears apart when bundler lives under an install prefix containing a space, and every child ruby under `bundle exec` dies at boot with "invalid switch in RUBYOPT". Fall back to requiring bundler/setup by feature name in that case; set_rubylib already puts our lib directory first on the child's load path, so the same bundler copy is still loaded. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The whitespace context stubs File.expand_path globally, so Gem.bin_path called from set_bundle_variables tries to open the fake path as a real gemspec stub and fails with ENOENT. Stub bin_path too, matching the existing special characters context. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Bundler::SharedHelpers#set_rubyoptinjects-r<absolute path to bundler/setup>intoRUBYOPT. Ruby splitsRUBYOPTon whitespace with no quoting mechanism, so when bundler lives under an install prefix containing a space (for exampleC:\Program Files), the path tears apart and every child ruby spawned underbundle execdies at boot withinvalid switch in RUBYOPT: -i.The absolute path was introduced in a5da088 so that child processes never leak to a different bundler copy. That property is kept for all currently working setups: the absolute form is still used whenever the path has no whitespace. Only in the space-containing case, which today fails unconditionally, does
set_rubyoptfall back to requiringbundler/setupby feature name.set_rubylibalready puts bundler's lib directory first on the child's load path viaRUBYLIB(which isPATH_SEPARATOR-separated and therefore safe with spaces), so the child still resolves the same bundler copy. When bundler is the default gem inrubylibdir,RUBYLIBis not modified and the feature name resolves through the same ruby's default load path, again the same copy. TheBUNDLER_SETUPvariable is unaffected since it is consumed as a plainrequireargument inlib/rubygems.rbwhere spaces are harmless.Verified on Windows with a mswin Ruby 4.0.5 and the patched bundler copied under
V:\tmp\ruby with space\patched lib\:Related to #9695, which fixes the argv quoting half of the same space-path breakage.
🤖 Generated with Claude Code