Merge pull request #461 from DavidS/validate-hashes

validate_integer, validate_numeric: explicitely reject hashes in arrays
This commit is contained in:
TP Honey 2015-05-28 13:29:43 +01:00
commit c9b810cf36
4 changed files with 12 additions and 0 deletions

View file

@ -109,6 +109,7 @@ module Puppet::Parser::Functions
# check every element of the array
input.each_with_index do |arg, pos|
begin
raise TypeError if arg.is_a?(Hash)
arg = Integer(arg.to_s)
validator.call(arg)
rescue TypeError, ArgumentError

View file

@ -71,6 +71,7 @@ module Puppet::Parser::Functions
# check every element of the array
input.each_with_index do |arg, pos|
begin
raise TypeError if arg.is_a?(Hash)
arg = Float(arg.to_s)
validator.call(arg)
rescue TypeError, ArgumentError

View file

@ -62,6 +62,11 @@ describe Puppet::Parser::Functions.function(:validate_integer) do
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be an Integer or Array/)
end
it "should not compile when a Hash is passed as Array" do
Puppet[:code] = "validate_integer([{ 1 => 2 }])"
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be an Integer/)
end
it "should not compile when an explicitly undef variable is passed" do
Puppet[:code] = <<-'ENDofPUPPETcode'
$foo = undef

View file

@ -62,6 +62,11 @@ describe Puppet::Parser::Functions.function(:validate_numeric) do
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric or Array/)
end
it "should not compile when a Hash is passed in an Array" do
Puppet[:code] = "validate_numeric([{ 1 => 2 }])"
expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/)
end
it "should not compile when an explicitly undef variable is passed" do
Puppet[:code] = <<-'ENDofPUPPETcode'
$foo = undef