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.
This commit is contained in:
parent
a4f64d0148
commit
509e29043a
|
@ -66,7 +66,13 @@ module VagrantPlugins
|
||||||
# string or as an array.
|
# string or as an array.
|
||||||
def args_valid?
|
def args_valid?
|
||||||
return true if !args
|
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
|
end
|
||||||
|
|
||||||
def remote?
|
def remote?
|
||||||
|
|
|
@ -8,10 +8,10 @@ module VagrantPlugins
|
||||||
class Provisioner < Vagrant.plugin("2", :provisioner)
|
class Provisioner < Vagrant.plugin("2", :provisioner)
|
||||||
def provision
|
def provision
|
||||||
args = ""
|
args = ""
|
||||||
if config.args.is_a?(String)
|
if config.args.is_a?(String) or config.args.is_a?(Fixnum)
|
||||||
args = " #{config.args}"
|
args = " #{config.args.to_s}"
|
||||||
elsif config.args.is_a?(Array)
|
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(" ")}"
|
args = " #{args.join(" ")}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -53,5 +53,27 @@ describe "VagrantPlugins::Shell::Config" do
|
||||||
I18n.t("vagrant.provisioners.shell.args_bad_type")
|
I18n.t("vagrant.provisioners.shell.args_bad_type")
|
||||||
]
|
]
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue