summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/functions/floor.rb7
-rw-r--r--lib/puppet/parser/functions/is_domain_name.rb3
-rw-r--r--lib/puppet/parser/functions/is_float.rb3
-rw-r--r--lib/puppet/parser/functions/is_function_available.rb3
-rwxr-xr-xspec/acceptance/getparam_spec.rb2
-rwxr-xr-xspec/acceptance/is_float_spec.rb6
-rwxr-xr-xspec/acceptance/is_string_spec.rb2
7 files changed, 20 insertions, 6 deletions
diff --git a/lib/puppet/parser/functions/floor.rb b/lib/puppet/parser/functions/floor.rb
index a401923..9a6f014 100644
--- a/lib/puppet/parser/functions/floor.rb
+++ b/lib/puppet/parser/functions/floor.rb
@@ -8,7 +8,12 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "floor(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size != 1
- arg = arguments[0]
+ begin
+ arg = Float(arguments[0])
+ rescue TypeError, ArgumentError => e
+ raise(Puppet::ParseError, "floor(): Wrong argument type " +
+ "given (#{arguments[0]} for Numeric)")
+ end
raise(Puppet::ParseError, "floor(): Wrong argument type " +
"given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
diff --git a/lib/puppet/parser/functions/is_domain_name.rb b/lib/puppet/parser/functions/is_domain_name.rb
index 5826dc0..b3fee96 100644
--- a/lib/puppet/parser/functions/is_domain_name.rb
+++ b/lib/puppet/parser/functions/is_domain_name.rb
@@ -20,6 +20,9 @@ Returns true if the string passed to this function is a syntactically correct do
label_min_length=1
label_max_length=63
+ # Only allow string types
+ return false unless domain.is_a?(String)
+
# Allow ".", it is the top level domain
return true if domain == '.'
diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb
index 911f3c2..a2da943 100644
--- a/lib/puppet/parser/functions/is_float.rb
+++ b/lib/puppet/parser/functions/is_float.rb
@@ -15,6 +15,9 @@ Returns true if the variable passed to this function is a float.
value = arguments[0]
+ # Only allow Numeric or String types
+ return false unless value.is_a?(Numeric) or value.is_a?(String)
+
if value != value.to_f.to_s and !value.is_a? Float then
return false
else
diff --git a/lib/puppet/parser/functions/is_function_available.rb b/lib/puppet/parser/functions/is_function_available.rb
index 6cbd35c..6da82c8 100644
--- a/lib/puppet/parser/functions/is_function_available.rb
+++ b/lib/puppet/parser/functions/is_function_available.rb
@@ -15,6 +15,9 @@ true if the function exists, false if not.
"given #{arguments.size} for 1")
end
+ # Only allow String types
+ return false unless arguments[0].is_a?(String)
+
function = Puppet::Parser::Functions.function(arguments[0].to_sym)
function.is_a?(String) and not function.empty?
end
diff --git a/spec/acceptance/getparam_spec.rb b/spec/acceptance/getparam_spec.rb
index a84b2d1..91fc9a0 100755
--- a/spec/acceptance/getparam_spec.rb
+++ b/spec/acceptance/getparam_spec.rb
@@ -13,7 +13,7 @@ describe 'getparam function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op
notice(inline_template('getparam is <%= @o.inspect %>'))
EOS
- apply_manifest(pp, :expect_changes => true) do |r|
+ apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/getparam is true/)
end
end
diff --git a/spec/acceptance/is_float_spec.rb b/spec/acceptance/is_float_spec.rb
index 79b01f0..338ba58 100755
--- a/spec/acceptance/is_float_spec.rb
+++ b/spec/acceptance/is_float_spec.rb
@@ -7,7 +7,7 @@ describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op
pp = <<-EOS
$a = ['aaa.com','bbb','ccc']
$o = is_float($a)
- notice(inline_template('is_floats is <%= @o.inspect %>'))
+ notice(inline_template('is_float is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
@@ -18,7 +18,7 @@ describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op
pp = <<-EOS
$a = true
$o = is_float($a)
- notice(inline_template('is_floats is <%= @o.inspect %>'))
+ notice(inline_template('is_float is <%= @o.inspect %>'))
EOS
apply_manifest(pp, :catch_failures => true) do |r|
@@ -75,7 +75,7 @@ describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op
EOS
apply_manifest(pp, :catch_failures => true) do |r|
- expect(r.stdout).to match(/is_floats is false/)
+ expect(r.stdout).to match(/is_float is false/)
end
end
end
diff --git a/spec/acceptance/is_string_spec.rb b/spec/acceptance/is_string_spec.rb
index bda6cd7..94d8e96 100755
--- a/spec/acceptance/is_string_spec.rb
+++ b/spec/acceptance/is_string_spec.rb
@@ -50,7 +50,7 @@ describe 'is_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o
EOS
apply_manifest(pp, :catch_failures => true) do |r|
- expect(r.stdout).to match(/is_string is true/)
+ expect(r.stdout).to match(/is_string is false/)
end
end
it 'is_strings floats' do