From cf9f7a6b7e4ede7edd612fde33f7149f9c7f3385 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 27 May 2015 20:05:01 +0100 Subject: validate_integer, validate_numeric: explicitely reject hashes in arrays Without this patch, Ruby 1.8's Hash#to_s behaviour causes [{1=>2}] to be treated as "12" when validating values. --- spec/functions/validate_numeric_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'spec/functions/validate_numeric_spec.rb') diff --git a/spec/functions/validate_numeric_spec.rb b/spec/functions/validate_numeric_spec.rb index 1623a3d..c99d879 100755 --- a/spec/functions/validate_numeric_spec.rb +++ b/spec/functions/validate_numeric_spec.rb @@ -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 -- cgit v1.2.3