diff --git a/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb b/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb index 0f7e806e..ee588037 100644 --- a/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb +++ b/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb @@ -666,15 +666,16 @@ def mandatory_set_attributes(context) end # Parses the DSC resource type definition to retrieve the names of any attributes which are specifed as required strings + # # This is used to ensure that any nil values are converted to empty strings to match puppets expecetd value # @param context [Object] the Puppet runtime context to operate in and send feedback to # @param data [Hash] the hash of properties returned from the DSC resource # @return [Hash] returns a data hash with any nil values converted to empty strings def stringify_nil_attributes(context, data) nil_strings = data.select { |_name, value| value.nil? }.keys - string_attrs = context.type.attributes.select { |_name, properties| properties[:type] == 'String' }.keys - string_attrs.each do |attribute| - data[attribute] = '' if nil_strings.include?(attribute) + attributes = context.type.attributes.select { |_name, properties| properties[:type].match?(/^Optional\[(String|Enum)|^(String|Enum)/) } + attributes.each do |name, _properties| + data[name] = '' if nil_strings.include?(name) end data end