Merge pull request #4776 from reitermarkus/system-command-with-spaces

Fix executable with spaces.
This commit is contained in:
Markus Reiter 2018-08-29 19:58:01 +02:00 committed by GitHub
commit eddd864a7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -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

View File

@ -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