summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml5
-rw-r--r--lib/puppet/parser/functions/fqdn_rotate.rb4
-rw-r--r--lib/puppet/parser/functions/validate_integer.rb1
-rw-r--r--lib/puppet/parser/functions/validate_numeric.rb1
-rwxr-xr-xspec/functions/validate_integer_spec.rb5
-rwxr-xr-xspec/functions/validate_numeric_spec.rb5
6 files changed, 19 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml
index 58e62d9..371586b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -14,5 +14,10 @@ matrix:
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.1.5
env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes"
+ - rvm: 2.1.6
+ env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes"
+ allow_failures:
+ - rvm: 2.1.6
+ env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes"
notifications:
email: false
diff --git a/lib/puppet/parser/functions/fqdn_rotate.rb b/lib/puppet/parser/functions/fqdn_rotate.rb
index cf22d36..d9741a0 100644
--- a/lib/puppet/parser/functions/fqdn_rotate.rb
+++ b/lib/puppet/parser/functions/fqdn_rotate.rb
@@ -39,9 +39,9 @@ Rotates an array a random number of times based on a nodes fqdn.
if defined?(Random) == 'constant' && Random.class == Class
offset = Random.new(seed).rand(elements)
else
- srand(seed)
+ old_seed = srand(seed)
offset = rand(elements)
- srand()
+ srand(old_seed)
end
end
offset.times {
diff --git a/lib/puppet/parser/functions/validate_integer.rb b/lib/puppet/parser/functions/validate_integer.rb
index 995f8db..95da0c4 100644
--- a/lib/puppet/parser/functions/validate_integer.rb
+++ b/lib/puppet/parser/functions/validate_integer.rb
@@ -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
diff --git a/lib/puppet/parser/functions/validate_numeric.rb b/lib/puppet/parser/functions/validate_numeric.rb
index d2e4d16..3a14443 100644
--- a/lib/puppet/parser/functions/validate_numeric.rb
+++ b/lib/puppet/parser/functions/validate_numeric.rb
@@ -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
diff --git a/spec/functions/validate_integer_spec.rb b/spec/functions/validate_integer_spec.rb
index 3865c4f..e95da6a 100755
--- a/spec/functions/validate_integer_spec.rb
+++ b/spec/functions/validate_integer_spec.rb
@@ -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
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