Skip to content

Commit

Permalink
Merge pull request #346 from puppetlabs/CAT-2061
Browse files Browse the repository at this point in the history
(CAT-2061) Fix empty string nullification
  • Loading branch information
jordanbreen28 authored Sep 25, 2024
2 parents 78c3f26 + ccd3b58 commit 16018aa
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -682,16 +682,16 @@ def mandatory_set_attributes(context)
context.type.attributes.select { |_attribute, properties| properties[:mandatory_for_set] }.keys
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
# Parses the DSC resource type definition to retrieve the names of any attributes which are specified as required strings
# This is used to ensure that any nil values are converted to empty strings to match puppets expeceted 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)
nil_attributes = data.select { |_name, value| value.nil? }.keys
nil_attributes.each do |nil_attr|
attribute_type = context.type.attributes[nil_attr][:type]
data[nil_attr] = '' if (attribute_type.start_with?('Optional[Enum[', 'Enum[') && enum_values(context, nil_attr).include?('')) || attribute_type == 'String'
end
data
end
Expand Down

0 comments on commit 16018aa

Please sign in to comment.