From ed8ecd15e129260b454877d4462a5344d31d293f Mon Sep 17 00:00:00 2001 From: Mikhail Emelchenkov Date: Mon, 28 May 2018 20:34:56 +0500 Subject: [PATCH 1/2] Fix: `trigger` embedded plugin fails to exec scripts at paths contains spaces --- lib/vagrant/plugin/v2/trigger.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vagrant/plugin/v2/trigger.rb b/lib/vagrant/plugin/v2/trigger.rb index 471949840..63b5a9386 100644 --- a/lib/vagrant/plugin/v2/trigger.rb +++ b/lib/vagrant/plugin/v2/trigger.rb @@ -157,7 +157,7 @@ module Vagrant @machine.ui.detail(I18n.t("vagrant.trigger.run.inline", command: config.inline)) else - cmd = File.expand_path(config.path, @env.root_path) + cmd = File.expand_path(config.path, @env.root_path).shellescape args = Array(config.args) cmd << " #{args.join(' ')}" if !args.empty? cmd = Shellwords.split(cmd) From 5723c7181a4a4f531290e8de2d927f0a4a1887b1 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 14 Aug 2018 13:39:31 -0700 Subject: [PATCH 2/2] Add test for trigger run path with spaces --- test/unit/vagrant/plugin/v2/trigger_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/vagrant/plugin/v2/trigger_test.rb b/test/unit/vagrant/plugin/v2/trigger_test.rb index 75d041962..c4023ca88 100644 --- a/test/unit/vagrant/plugin/v2/trigger_test.rb +++ b/test/unit/vagrant/plugin/v2/trigger_test.rb @@ -131,7 +131,7 @@ describe Vagrant::Plugin::V2::Trigger do {info: "hi", run: {inline: "echo 'hi'", env: {"KEY"=>"VALUE"}}, exit_codes: [0,50]} } let(:path_block) { {warn: "bye", - run: {path: "script.sh", args: "HELLO", env: {"KEY"=>"VALUE"}}, + run: {path: "path/to the/script.sh", args: "HELLO", env: {"KEY"=>"VALUE"}}, on_error: :continue} } let(:path_block_ps1) { {warn: "bye", @@ -227,7 +227,7 @@ describe Vagrant::Plugin::V2::Trigger do exit_codes = trigger.exit_codes expect(Vagrant::Util::Subprocess).to receive(:execute). - with("/vagrant/home/script.sh", "HELLO", options) + with("/vagrant/home/path/to the/script.sh", "HELLO", options) subject.send(:run, shell_config, on_error, exit_codes) end @@ -243,7 +243,7 @@ describe Vagrant::Plugin::V2::Trigger do exit_codes = trigger.exit_codes expect(Vagrant::Util::Subprocess).to receive(:execute). - with("/vagrant/home/script.sh", "HELLO", options) + with("/vagrant/home/path/to the/script.sh", "HELLO", options) subject.send(:run, shell_config, on_error, exit_codes) end