From ad7054cc887e2a0aaa0758a24499df5111a45ff4 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 29 Aug 2018 19:23:30 +0200 Subject: [PATCH] Fix executable with spaces. --- Library/Homebrew/system_command.rb | 2 +- Library/Homebrew/test/system_command_spec.rb | 21 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index afa721547f..4eef3e6644 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -119,7 +119,7 @@ class SystemCommand executable, *args = command raw_stdin, raw_stdout, raw_stderr, raw_wait_thr = - Open3.popen3(env, executable, *args, **options) + Open3.popen3(env, [executable, executable], *args, **options) write_input_to(raw_stdin) raw_stdin.close_write diff --git a/Library/Homebrew/test/system_command_spec.rb b/Library/Homebrew/test/system_command_spec.rb index 6f98b7a5a3..118499c0d6 100644 --- a/Library/Homebrew/test/system_command_spec.rb +++ b/Library/Homebrew/test/system_command_spec.rb @@ -21,7 +21,7 @@ describe SystemCommand do it "includes the given variables explicitly" do expect(Open3) .to receive(:popen3) - .with(an_instance_of(Hash), "env", "A=1", "B=2", "C=3", "env", *env_args, {}) + .with(an_instance_of(Hash), ["env", "env"], "A=1", "B=2", "C=3", "env", *env_args, {}) .and_call_original command.run! @@ -46,7 +46,7 @@ describe SystemCommand do it "includes the given variables explicitly" do expect(Open3) .to receive(:popen3) - .with(an_instance_of(Hash), "/usr/bin/sudo", "-E", "--", + .with(an_instance_of(Hash), ["/usr/bin/sudo", "/usr/bin/sudo"], "-E", "--", "env", "A=1", "B=2", "C=3", "env", *env_args, {}) .and_wrap_original do |original_popen3, *_, &block| original_popen3.call("true", &block) @@ -227,5 +227,22 @@ describe SystemCommand do args: ["-c", 'printf "\r%s" "################### 27.6%" 1>&2'] }.to output("\r################### 27.6%").to_stderr end + + context "when given an executable with spaces and no arguments" do + let(:executable) { mktmpdir/"App Uninstaller" } + + before(:each) do + executable.write <<~SH + #!/usr/bin/env bash + true + SH + + FileUtils.chmod "+x", executable + end + + it "does not interpret the executable as a shell line" do + expect(system_command(executable)).to be_a_success + end + end end end