Skip to content

Commit 0d93ca9

Browse files
authored
Merge pull request #852 from puppetlabs/master
Min function correction
2 parents 9c2873b + 9b30b1b commit 0d93ca9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/puppet/parser/functions/min.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ module Puppet::Parser::Functions
1313
# Sometimes we get numbers as numerics and sometimes as strings.
1414
# We try to compare them as numbers when possible
1515
return args.min do |a, b|
16-
a.to_f <=> b.to_f if a.to_s =~ %r{\A^-?\d+(.\d+)?\z} && b.to_s =~ %r{\A-?\d+(.\d+)?\z}
17-
a.to_s <=> b.to_s
16+
if a.to_s =~ %r{\A^-?\d+(.\d+)?\z} && b.to_s =~ %r{\A-?\d+(.\d+)?\z}
17+
a.to_f <=> b.to_f
18+
else
19+
a.to_s <=> b.to_s
20+
end
1821
end
1922
end
2023
end

spec/functions/min_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
it { is_expected.to run.with_params(1, 2).and_return(1) }
88
it { is_expected.to run.with_params(1, 2, 3).and_return(1) }
99
it { is_expected.to run.with_params(3, 2, 1).and_return(1) }
10+
it { is_expected.to run.with_params(12, 8).and_return(8) }
1011
it { is_expected.to run.with_params('one').and_return('one') }
1112
it { is_expected.to run.with_params('one', 'two').and_return('one') }
1213
it { is_expected.to run.with_params('one', 'two', 'three').and_return('one') }

0 commit comments

Comments
 (0)