summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions
diff options
context:
space:
mode:
authorAdrien Thebo <git@somethingsinistral.net>2013-03-27 14:04:19 -0700
committerAdrien Thebo <git@somethingsinistral.net>2013-03-27 14:04:19 -0700
commit4078a6ff44c3ea8c2a071eec3bd7b02dabc770d7 (patch)
treeadc39db79f94c0427250f3bf39cb1fadda49dc15 /lib/puppet/parser/functions
parentf0db049924674b6221a272d1b04a0d4131c47674 (diff)
parent0adcf646b85ea3379ac8cb25050d445e577b71a3 (diff)
downloadpuppet-stdlib-4078a6ff44c3ea8c2a071eec3bd7b02dabc770d7.tar.gz
puppet-stdlib-4078a6ff44c3ea8c2a071eec3bd7b02dabc770d7.tar.bz2
Merge branch '4.x'
Diffstat (limited to 'lib/puppet/parser/functions')
-rw-r--r--lib/puppet/parser/functions/max.rb10
-rw-r--r--lib/puppet/parser/functions/min.rb10
2 files changed, 18 insertions, 2 deletions
diff --git a/lib/puppet/parser/functions/max.rb b/lib/puppet/parser/functions/max.rb
index 10b6f74..60fb94a 100644
--- a/lib/puppet/parser/functions/max.rb
+++ b/lib/puppet/parser/functions/max.rb
@@ -8,6 +8,14 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "max(): Wrong number of arguments " +
"need at least one") if args.size == 0
- return args.max
+ # Sometimes we get numbers as numerics and sometimes as strings.
+ # We try to compare them as numbers when possible
+ return args.max do |a,b|
+ if a.to_s =~ /\A-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then
+ a.to_f <=> b.to_f
+ else
+ a.to_s <=> b.to_s
+ end
+ end
end
end
diff --git a/lib/puppet/parser/functions/min.rb b/lib/puppet/parser/functions/min.rb
index abf1b62..6bd6ebf 100644
--- a/lib/puppet/parser/functions/min.rb
+++ b/lib/puppet/parser/functions/min.rb
@@ -8,6 +8,14 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "min(): Wrong number of arguments " +
"need at least one") if args.size == 0
- return args.min
+ # Sometimes we get numbers as numerics and sometimes as strings.
+ # We try to compare them as numbers when possible
+ return args.min do |a,b|
+ if a.to_s =~ /\A^-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then
+ a.to_f <=> b.to_f
+ else
+ a.to_s <=> b.to_s
+ end
+ end
end
end