Repository navigation
Fix bundle exec with no arguments for paths containing spaces - #9996
Merged
Merged
Conversation
When an executable can't be loaded directly and no arguments are passed, Kernel.exec only receives the path and an options hash. Ruby treats that as a command line and splits it on whitespace, so a path with a space in it fails with ENOENT and Bundler reports `command not found`. Pass the path as a `[path, argv0]` pair, so that Ruby always runs it literally. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hsbt
approved these changes
Nov 4, 2026
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 <command>fails withcommand not foundwhen all of these are true:~/Library/Application Support/...on macOSKernel.exec, for example because it has a#!/bin/shshebangThe executable exists, and
Bundler.whichfinds it. The same command works if you pass any argument.This breaks Ruby LSP in Zed on macOS when using a Ruby built with
--enable-load-relative, such as mise's precompiled Rubies. The Zed extension runsgem installinto a directory underApplication Support, which generates a#!/bin/shbinstub. Ruby LSP then starts itself withbundle exec ruby-lsp:To reproduce, without any of that tooling:
What is your fix for the problem, implemented in this PR?
With no arguments,
CLI::Exec#runcallsKernel.exec(bin_path, { close_others: true }).Kernel.exectreats a single string as a command line and splits it on whitespace, so it looks for an executable at the path up to the first space. That raisesErrno::ENOENT, which Bundler reports ascommand not found.With one or more arguments, Ruby already runs the path literally, which is why only the no-argument case fails.
This passes the path as a
[path, argv0]pair, which always runs it literally. It also means shell metacharacters in a resolved path are no longer interpreted.The
kernel_exec(cmd, *args)fallback is unchanged. It's used whenBundler.whichfinds nothing, and commands likebundle exec 'cd foo && bar'depend on it going through the shell.I tested this on macOS with Ruby 4.0.6 and haven't tested it on Windows or JRuby.
Make sure the following tasks are checked