Skip to content

Commit 792bcd4

Browse files
committed
(MODULES-7768) Handle nil in delete_undef_values() function
PUP-9112 changed use of `:undef` inside structured values to instead using `nil` in Puppet 6.0.0. The `delete_undef_values()` function was not prepared to handle this and would not delete `nil` from `Array` or `Hash` values. This commit fixes this problem.
1 parent f357cf4 commit 792bcd4

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

lib/puppet/parser/functions/delete_undef_values.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ module Puppet::Parser::Functions
3030
end
3131
result = args[0].dup
3232
if result.is_a?(Hash)
33-
result.delete_if { |_key, val| val.equal? :undef }
33+
result.delete_if { |_, val| val.equal?(:undef) || val.nil? }
3434
elsif result.is_a?(Array)
3535
result.delete :undef
36+
result.delete nil
3637
end
3738
result
3839
end

spec/functions/delete_undef_values_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
describe "when undef is represented by #{undef_value.inspect}" do
1313
before(:each) do
1414
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == ''
15-
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value.nil?
1615
end
1716
it { is_expected.to run.with_params([undef_value]).and_return([]) }
1817
it { is_expected.to run.with_params(['one', undef_value, 'two', 'three']).and_return(['one', 'two', 'three']) }
@@ -35,7 +34,6 @@
3534
describe "when undef is represented by #{undef_value.inspect}" do
3635
before(:each) do
3736
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == ''
38-
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value.nil?
3937
end
4038
it { is_expected.to run.with_params('key' => undef_value).and_return({}) }
4139
it {

0 commit comments

Comments
 (0)