From fe85f467c8f8e65c9fd09acff17ac4adb80f12b8 Mon Sep 17 00:00:00 2001 From: Dan Bode Date: Mon, 13 Aug 2012 18:52:00 -0700 Subject: Handle undef for parameter argument This commit adds better handling of the case where undef is passed as the parameter value. This works by converting '' into [] --- lib/puppet/parser/functions/defined_with_params.rb | 4 +++- spec/functions/defined_with_params_spec.rb | 1 + spec/functions/ensure_resource_spec.rb | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index e09e41c..d7df306 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -20,7 +20,9 @@ ENDOFDOC ) do |vals| reference, params = vals raise(ArgumentError, 'Must specify a reference') unless reference - params ||= {} + if (! params) || params == '' + params = {} + end ret = false if resource = findresource(reference.to_s) matches = params.collect do |key, value| diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index 21c08a0..f995b67 100644 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -26,6 +26,7 @@ describe 'defined_with_params' do should run.with_params('User[dan]', {'ensure' => 'present'}).and_return(true) should run.with_params('User[dan]', {'ensure' => 'present', 'managehome' => false}).and_return(true) should run.with_params('User[dan]', {'ensure' => 'absent', 'managehome' => false}).and_return(false) + should run.with_params('User[dan]', '').and_return(true) end end end diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index e45a6d0..e03efda 100644 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -26,6 +26,7 @@ describe 'ensure_resource' do it do # these first three should not fail should run.with_params('User', 'dan', {}) + should run.with_params('User', 'dan', '') should run.with_params('User', 'dan', {'ensure' => 'present'}) should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false}) # test that this fails -- cgit v1.2.3