From e073153728bb86b1985f94aab4f17996322f9c35 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 14 Aug 2018 09:30:11 -0700 Subject: [PATCH] (#10099) Properly join commands from passed in array Prior to this commit, the `Util::Powershell.execute_inline` method didn't properly join the passed in command and instead attempted to execute the array of strings. This commit updates that behavior to join the command array prior to inserting it into the full powershell command. --- lib/vagrant/util/powershell.rb | 3 +++ test/unit/vagrant/util/powershell_test.rb | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/vagrant/util/powershell.rb b/lib/vagrant/util/powershell.rb index d8529f423..9f76b730f 100644 --- a/lib/vagrant/util/powershell.rb +++ b/lib/vagrant/util/powershell.rb @@ -132,6 +132,9 @@ module Vagrant if env = opts.delete(:env) env = env.map{|k,v| "$env:#{k}=#{v}"}.join(";") + "; " end + + command = command.join(' ') + c = [ executable, "-NoLogo", diff --git a/test/unit/vagrant/util/powershell_test.rb b/test/unit/vagrant/util/powershell_test.rb index 00c544427..6fe9d08db 100644 --- a/test/unit/vagrant/util/powershell_test.rb +++ b/test/unit/vagrant/util/powershell_test.rb @@ -215,6 +215,7 @@ describe Vagrant::Util::PowerShell do let(:exit_code){ 0 } let(:stdout){ "" } let(:stderr){ "" } + let(:command) { ["run", "--this", "custom-command"] } before do allow(described_class).to receive(:validate_install!) @@ -223,7 +224,7 @@ describe Vagrant::Util::PowerShell do it "should validate installation before use" do expect(described_class).to receive(:validate_install!) - described_class.execute_inline("command") + described_class.execute_inline(command) end it "should include command to execute" do @@ -232,7 +233,7 @@ describe Vagrant::Util::PowerShell do expect(comm.to_s).to include("custom-command") result end - described_class.execute_inline("custom-command") + described_class.execute_inline(command) end it "should accept custom environment" do @@ -241,7 +242,7 @@ describe Vagrant::Util::PowerShell do expect(comm.to_s).to include("$env:TEST_KEY=test-value") result end - described_class.execute_inline("custom-command", env: {"TEST_KEY" => "test-value"}) + described_class.execute_inline(command, env: {"TEST_KEY" => "test-value"}) end it "should define a custom module path" do @@ -250,11 +251,11 @@ describe Vagrant::Util::PowerShell do expect(comm.to_s).to include("$env:PSModulePath+';C:\\My-Path'") result end - described_class.execute_inline("custom-command", module_path: "C:\\My-Path") + described_class.execute_inline(command, module_path: "C:\\My-Path") end it "should return a result instance" do - expect(described_class.execute_inline("cmd")).to eq(result) + expect(described_class.execute_inline(command)).to eq(result) end end