summaryrefslogtreecommitdiff
path: root/lib/puppet/parser
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/parser')
-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
4 files changed, 15 insertions, 1 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