Skip to content

Commit 29e551a

Browse files
committed
Use /bin/sh -c instead of true &&
1 parent f642040 commit 29e551a

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

lib/spoom/context/exec.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# typed: strict
22
# frozen_string_literal: true
33

4+
require "shellwords"
5+
46
module Spoom
57
class ExecResult < T::Struct
68
const :out, String
@@ -30,11 +32,15 @@ def exec(command, capture_err: true)
3032
Bundler.with_unbundled_env do
3133
opts = { chdir: absolute_path } #: Hash[Symbol, untyped]
3234

33-
# Work around Open3 buffering bug in certain Ruby builds (e.g., Nix Ruby).
34-
# Direct binary execution via Open3.capture3 can produce corrupted output.
35-
# Prepending "true &&" forces Ruby to invoke the shell, which prevents corruption.
36-
# The "true" command is a no-op that always succeeds.
37-
command_with_shell = "true && #{command}"
35+
# When Ruby is wrapped in another dev environment (e.g. Nix), that environment might set
36+
# env variables that cause Sorbet (or other tools) to link to incorrect versions of
37+
# dependencies.
38+
#
39+
# In the case of Sorbet, this can lead to corrupted JSON output.
40+
#
41+
# Executing the command directly through the shell bypasses any Ruby wrappers and
42+
# ensures that we are using the versions of tools that are default on the system.
43+
command_with_shell = "/bin/sh -c #{command.shellescape}"
3844

3945
if capture_err
4046
out, err, status = Open3.capture3(command_with_shell, opts)

0 commit comments

Comments
 (0)