Skip to content

Commit 4001eb1

Browse files
Merge pull request #292 from Clebam/fix_empty_string_nullification
Fix empty string nullification
2 parents 900a944 + 3c1b39e commit 4001eb1

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,16 +665,16 @@ def mandatory_set_attributes(context)
665665
context.type.attributes.select { |_attribute, properties| properties[:mandatory_for_set] }.keys
666666
end
667667

668-
# Parses the DSC resource type definition to retrieve the names of any attributes which are specifed as required strings
669-
# This is used to ensure that any nil values are converted to empty strings to match puppets expecetd value
668+
# Parses the DSC resource type definition to retrieve the names of any attributes which are specified as required strings
669+
# This is used to ensure that any nil values are converted to empty strings to match puppets expected value
670670
# @param context [Object] the Puppet runtime context to operate in and send feedback to
671671
# @param data [Hash] the hash of properties returned from the DSC resource
672672
# @return [Hash] returns a data hash with any nil values converted to empty strings
673673
def stringify_nil_attributes(context, data)
674-
nil_strings = data.select { |_name, value| value.nil? }.keys
675-
string_attrs = context.type.attributes.select { |_name, properties| properties[:type] == 'String' }.keys
676-
string_attrs.each do |attribute|
677-
data[attribute] = '' if nil_strings.include?(attribute)
674+
nil_attributes = data.select { |_name, value| value.nil? }.keys
675+
nil_attributes.each do |nil_attr|
676+
attribute_type = context.type.attributes[nil_attr][:type]
677+
data[nil_attr] = '' if (attribute_type.include?('Enum[') && enum_values(context, nil_attr).include?('')) || attribute_type == 'String'
678678
end
679679
data
680680
end

lib/puppet/provider/dsc_base_provider/invoke_dsc_resource_functions.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,4 @@ Function ConvertTo-CanonicalResult {
123123

124124
# Output the final result
125125
$ResultObject
126-
}
126+
}

0 commit comments

Comments
 (0)