Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Fix bundle exec with no arguments for paths containing spaces - #9996

Merged
hsbt merged 1 commit into
ruby:masterfrom
brandonweiss:fix-bundle-exec-path-with-spaces
Nov 4, 2026
Merged

hsbt merged 1 commit into
ruby:masterfrom
brandonweiss:fix-bundle-exec-path-with-spaces

Conversation

@brandonweiss

Copy link
Copy Markdown
Contributor

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

bundle exec <command> fails with command not found when all of these are true:

  • The executable's path contains a space, such as ~/Library/Application Support/... on macOS
  • The command is run with no arguments
  • Bundler can't load the executable directly and falls back to Kernel.exec, for example because it has a #!/bin/sh shebang

The executable exists, and Bundler.which finds 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 runs gem install into a directory under Application Support, which generates a #!/bin/sh binstub. Ruby LSP then starts itself with bundle exec ruby-lsp:

bundler: command not found: ruby-lsp
Install missing gem executables with `bundle install`

To reproduce, without any of that tooling:

bundle init
mkdir "dir with spaces"
printf '#!/bin/sh\necho hello\n' > "dir with spaces/script"
chmod +x "dir with spaces/script"
PATH="$PWD/dir with spaces:$PATH" bundle exec script

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

With no arguments, CLI::Exec#run calls Kernel.exec(bin_path, { close_others: true }). Kernel.exec treats 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 raises Errno::ENOENT, which Bundler reports as command 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 when Bundler.which finds nothing, and commands like bundle 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

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
hsbt merged commit 895b329 into ruby:master Nov 4, 2026
114 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants