Skip to content

Commit

Permalink
(MODULES-7768) Handle nil in delete_undef_values() function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hlindberg committed Sep 9, 2018
1 parent f357cf4 commit 792bcd4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/puppet/parser/functions/delete_undef_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ module Puppet::Parser::Functions
end
result = args[0].dup
if result.is_a?(Hash)
result.delete_if { |_key, val| val.equal? :undef }
result.delete_if { |_, val| val.equal?(:undef) || val.nil? }
elsif result.is_a?(Array)
result.delete :undef
result.delete nil
end
result
end
Expand Down
2 changes: 0 additions & 2 deletions spec/functions/delete_undef_values_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
describe "when undef is represented by #{undef_value.inspect}" do
before(:each) do
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == ''
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value.nil?
end
it { is_expected.to run.with_params([undef_value]).and_return([]) }
it { is_expected.to run.with_params(['one', undef_value, 'two', 'three']).and_return(['one', 'two', 'three']) }
Expand All @@ -35,7 +34,6 @@
describe "when undef is represented by #{undef_value.inspect}" do
before(:each) do
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value == ''
pending("review behaviour when being passed undef as #{undef_value.inspect}") if undef_value.nil?
end
it { is_expected.to run.with_params('key' => undef_value).and_return({}) }
it {
Expand Down

0 comments on commit 792bcd4

Please sign in to comment.