Skip to content

Commit 16018aa

Browse files
Merge pull request #346 from puppetlabs/CAT-2061
(CAT-2061) Fix empty string nullification
2 parents 78c3f26 + ccd3b58 commit 16018aa

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -682,16 +682,16 @@ def mandatory_set_attributes(context)
682682
context.type.attributes.select { |_attribute, properties| properties[:mandatory_for_set] }.keys
683683
end
684684

685-
# Parses the DSC resource type definition to retrieve the names of any attributes which are specifed as required strings
686-
# This is used to ensure that any nil values are converted to empty strings to match puppets expecetd value
685+
# Parses the DSC resource type definition to retrieve the names of any attributes which are specified as required strings
686+
# This is used to ensure that any nil values are converted to empty strings to match puppets expeceted value
687687
# @param context [Object] the Puppet runtime context to operate in and send feedback to
688688
# @param data [Hash] the hash of properties returned from the DSC resource
689689
# @return [Hash] returns a data hash with any nil values converted to empty strings
690690
def stringify_nil_attributes(context, data)
691-
nil_strings = data.select { |_name, value| value.nil? }.keys
692-
string_attrs = context.type.attributes.select { |_name, properties| properties[:type] == 'String' }.keys
693-
string_attrs.each do |attribute|
694-
data[attribute] = '' if nil_strings.include?(attribute)
691+
nil_attributes = data.select { |_name, value| value.nil? }.keys
692+
nil_attributes.each do |nil_attr|
693+
attribute_type = context.type.attributes[nil_attr][:type]
694+
data[nil_attr] = '' if (attribute_type.start_with?('Optional[Enum[', 'Enum[') && enum_values(context, nil_attr).include?('')) || attribute_type == 'String'
695695
end
696696
data
697697
end

0 commit comments

Comments
 (0)