From 509e29043a9a2bd63fed5d617da3daabaff856cf Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Fri, 14 Feb 2014 11:47:36 -0800 Subject: [PATCH 1/3] Added handling of fixnum values for shell provisioner options both as the value of `args` itself and as an element inside of an `args` array. Added validation around passing in arrays for arguments. Just knowing that it is an array is not enough, because arrays can contain any other type. --- plugins/provisioners/shell/config.rb | 8 ++++++- plugins/provisioners/shell/provisioner.rb | 6 ++--- .../plugins/provisioners/shell/config_test.rb | 22 +++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/plugins/provisioners/shell/config.rb b/plugins/provisioners/shell/config.rb index 931fadd14..c0b0b7cf2 100644 --- a/plugins/provisioners/shell/config.rb +++ b/plugins/provisioners/shell/config.rb @@ -66,7 +66,13 @@ module VagrantPlugins # string or as an array. def args_valid? return true if !args - args.is_a?(String) || args.is_a?(Array) + return true if args.is_a?(String) or args.is_a?(Fixnum) + if args.is_a?(Array) + args.each do |a| + return false if not a.kind_of?(String) and not a.kind_of?(Fixnum) + end + return true + end end def remote? diff --git a/plugins/provisioners/shell/provisioner.rb b/plugins/provisioners/shell/provisioner.rb index e258286bf..04ee3c8ef 100644 --- a/plugins/provisioners/shell/provisioner.rb +++ b/plugins/provisioners/shell/provisioner.rb @@ -8,10 +8,10 @@ module VagrantPlugins class Provisioner < Vagrant.plugin("2", :provisioner) def provision args = "" - if config.args.is_a?(String) - args = " #{config.args}" + if config.args.is_a?(String) or config.args.is_a?(Fixnum) + args = " #{config.args.to_s}" elsif config.args.is_a?(Array) - args = config.args.map { |a| quote_and_escape(a) } + args = config.args.map { |a| quote_and_escape(a.to_s) } args = " #{args.join(" ")}" end diff --git a/test/unit/plugins/provisioners/shell/config_test.rb b/test/unit/plugins/provisioners/shell/config_test.rb index 2716afb43..13aa531c6 100644 --- a/test/unit/plugins/provisioners/shell/config_test.rb +++ b/test/unit/plugins/provisioners/shell/config_test.rb @@ -53,5 +53,27 @@ describe "VagrantPlugins::Shell::Config" do I18n.t("vagrant.provisioners.shell.args_bad_type") ] end + + it "handles scalar array args" do + subject.path = file_that_exists + subject.args = ["string", 1, 2] + subject.finalize! + + result = subject.validate(machine) + + result["shell provisioner"].should == [] + end + + it "returns an error if args is an array with non-scalar types" do + subject.path = file_that_exists + subject.args = [[1]] + subject.finalize! + + result = subject.validate(machine) + + result["shell provisioner"].should == [ + I18n.t("vagrant.provisioners.shell.args_bad_type") + ] + end end end From fff4f595c517dc64284a60ba1347a84fc8474b99 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Fri, 14 Feb 2014 11:53:17 -0800 Subject: [PATCH 2/3] Added unit test for passing a single fixnum as an argument to the shell provisioner --- test/unit/plugins/provisioners/shell/config_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/unit/plugins/provisioners/shell/config_test.rb b/test/unit/plugins/provisioners/shell/config_test.rb index 13aa531c6..3e5c6f516 100644 --- a/test/unit/plugins/provisioners/shell/config_test.rb +++ b/test/unit/plugins/provisioners/shell/config_test.rb @@ -30,6 +30,17 @@ describe "VagrantPlugins::Shell::Config" do result["shell provisioner"].should == [] end + it "passes with fixnum args" do + subject.path = file_that_exists + subject.args = 1 + subject.finalize! + + result = subject.validate(machine) + + result["shell provisioner"].should == [] + end + + it "passes with array args" do subject.path = file_that_exists subject.args = ["an", "array"] From a4e923bec75ada8c9eb925729fb8a26ef5cefeeb Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Fri, 14 Feb 2014 12:02:27 -0800 Subject: [PATCH 3/3] Removed excess whitespace --- test/unit/plugins/provisioners/shell/config_test.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/plugins/provisioners/shell/config_test.rb b/test/unit/plugins/provisioners/shell/config_test.rb index 3e5c6f516..8b05f452b 100644 --- a/test/unit/plugins/provisioners/shell/config_test.rb +++ b/test/unit/plugins/provisioners/shell/config_test.rb @@ -40,7 +40,6 @@ describe "VagrantPlugins::Shell::Config" do result["shell provisioner"].should == [] end - it "passes with array args" do subject.path = file_that_exists subject.args = ["an", "array"]