diff --git a/lib/puppet/parser/functions/min.rb b/lib/puppet/parser/functions/min.rb index a2ec99f44..712902dc3 100644 --- a/lib/puppet/parser/functions/min.rb +++ b/lib/puppet/parser/functions/min.rb @@ -13,8 +13,11 @@ module Puppet::Parser::Functions # 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| - a.to_f <=> b.to_f if a.to_s =~ %r{\A^-?\d+(.\d+)?\z} && b.to_s =~ %r{\A-?\d+(.\d+)?\z} - a.to_s <=> b.to_s + if a.to_s =~ %r{\A^-?\d+(.\d+)?\z} && b.to_s =~ %r{\A-?\d+(.\d+)?\z} + a.to_f <=> b.to_f + else + a.to_s <=> b.to_s + end end end end diff --git a/spec/functions/min_spec.rb b/spec/functions/min_spec.rb index fd2c9227e..2c325a4eb 100755 --- a/spec/functions/min_spec.rb +++ b/spec/functions/min_spec.rb @@ -7,6 +7,7 @@ it { is_expected.to run.with_params(1, 2).and_return(1) } it { is_expected.to run.with_params(1, 2, 3).and_return(1) } it { is_expected.to run.with_params(3, 2, 1).and_return(1) } + it { is_expected.to run.with_params(12, 8).and_return(8) } it { is_expected.to run.with_params('one').and_return('one') } it { is_expected.to run.with_params('one', 'two').and_return('one') } it { is_expected.to run.with_params('one', 'two', 'three').and_return('one') }