File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed
lib/puppet/parser/functions
spec/unit/puppet/parser/functions Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,14 @@ module Puppet::Parser::Functions
88 raise ( Puppet ::ParseError , "max(): Wrong number of arguments " +
99 "need at least one" ) if args . size == 0
1010
11- return args . max
11+ # Sometimes we get numbers as numerics and sometimes as strings.
12+ # We try to compare them as numbers when possible
13+ return args . max do |a , b |
14+ if a . to_s =~ /\A -?\d +(.\d +)?\z / and b . to_s =~ /\A -?\d +(.\d +)?\z / then
15+ a . to_f <=> b . to_f
16+ else
17+ a . to_s <=> b . to_s
18+ end
19+ end
1220 end
1321end
Original file line number Diff line number Diff line change @@ -8,6 +8,14 @@ module Puppet::Parser::Functions
88 raise ( Puppet ::ParseError , "min(): Wrong number of arguments " +
99 "need at least one" ) if args . size == 0
1010
11- return args . min
11+ # Sometimes we get numbers as numerics and sometimes as strings.
12+ # We try to compare them as numbers when possible
13+ return args . min do |a , b |
14+ if a . to_s =~ /\A ^-?\d +(.\d +)?\z / and b . to_s =~ /\A -?\d +(.\d +)?\z / then
15+ a . to_f <=> b . to_f
16+ else
17+ a . to_s <=> b . to_s
18+ end
19+ end
1220 end
1321end
Original file line number Diff line number Diff line change 2020 it "should be able to compare numbers" do
2121 scope . function_max ( [ 6 , 8 , 4 ] ) . should ( eq ( 8 ) )
2222 end
23+
24+ it "should be able to compare a number with a stringified number" do
25+ scope . function_max ( [ 1 , "2" ] ) . should ( eq ( "2" ) )
26+ end
2327end
Original file line number Diff line number Diff line change 2020 it "should be able to compare numbers" do
2121 scope . function_min ( [ 6 , 8 , 4 ] ) . should ( eq ( 4 ) )
2222 end
23+
24+ it "should be able to compare a number with a stringified number" do
25+ scope . function_min ( [ 1 , "2" ] ) . should ( eq ( 1 ) )
26+ end
2327end
You can’t perform that action at this time.
0 commit comments