From 29aba535cef438d3e074d78e061df0b54b2fffb0 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 14 Aug 2018 10:26:57 -0700 Subject: [PATCH] (#10104) Ensure trigger run args are an array prior to join Prior to this commit, if the args key was a string rather than an array of strings, the `join` command would fail when appending the arguments to the run command for a given script. This commit updates that by ensuring the `args` option is an array prior to joining the arguments. --- lib/vagrant/plugin/v2/trigger.rb | 3 ++- test/unit/vagrant/plugin/v2/trigger_test.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/plugin/v2/trigger.rb b/lib/vagrant/plugin/v2/trigger.rb index 67f6643fe..471949840 100644 --- a/lib/vagrant/plugin/v2/trigger.rb +++ b/lib/vagrant/plugin/v2/trigger.rb @@ -158,7 +158,8 @@ 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 << " #{config.args.join(' ' )}" if config.args + args = Array(config.args) + cmd << " #{args.join(' ')}" if !args.empty? cmd = Shellwords.split(cmd) @machine.ui.detail(I18n.t("vagrant.trigger.run.script", path: config.path)) diff --git a/test/unit/vagrant/plugin/v2/trigger_test.rb b/test/unit/vagrant/plugin/v2/trigger_test.rb index 1bf09ff44..66750d613 100644 --- a/test/unit/vagrant/plugin/v2/trigger_test.rb +++ b/test/unit/vagrant/plugin/v2/trigger_test.rb @@ -131,11 +131,11 @@ 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", env: {"KEY"=>"VALUE"}}, + run: {path: "script.sh", args: "HELLO", env: {"KEY"=>"VALUE"}}, on_error: :continue} } let(:path_block_ps1) { {warn: "bye", - run: {path: "script.ps1", env: {"KEY"=>"VALUE"}}, + run: {path: "script.ps1", args: ["HELLO", "THERE"], env: {"KEY"=>"VALUE"}}, on_error: :continue} } let(:exit_code) { 0 }