Skip to content

Commit 6f1d164

Browse files
roman-muellerHelen Campbell
authored andcommitted
Check for numeric values as empty fails on those
1 parent 48b658f commit 6f1d164

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/puppet/parser/functions/empty.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ module Puppet::Parser::Functions
1313

1414
value = arguments[0]
1515

16-
unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String)
16+
unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String) || value.is_a?(Numeric)
1717
raise(Puppet::ParseError, 'empty(): Requires either ' +
18-
'array, hash or string to work with')
18+
'array, hash, string or integer to work with')
1919
end
2020

21-
result = value.empty?
21+
if value.is_a?(Numeric)
22+
return false
23+
else
24+
result = value.empty?
2225

23-
return result
26+
return result
27+
end
2428
end
2529
end
2630

spec/functions/empty_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
describe 'empty' do
44
it { is_expected.not_to eq(nil) }
55
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) }
6-
it { is_expected.to run.with_params(0).and_raise_error(Puppet::ParseError) }
76
it {
87
pending("Current implementation ignores parameters after the first.")
98
is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError)
109
}
10+
it { is_expected.to run.with_params(0).and_return(false) }
1111
it { is_expected.to run.with_params('').and_return(true) }
1212
it { is_expected.to run.with_params('one').and_return(false) }
1313

0 commit comments

Comments
 (0)