Skip to content

Commit

Permalink
Allow but filter out empty strings in build_dn
Browse files Browse the repository at this point in the history
There exists the possibility a parameter passed to build_dn could be
an empty string which breaks the previous requirement on a string
of length at least one, String[1]. Change to accept any length string
but if the string happens to be empty, filter it out of the calculation.
  • Loading branch information
ehelms committed Feb 1, 2023
1 parent 06b5098 commit c815b5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/puppet/functions/katello/build_dn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
Puppet::Functions.create_function(:'katello::build_dn') do
# @param options
dispatch :build_dn do
param 'Array[Tuple[String[1], Optional[String[1]]]]', :options
param 'Array[Tuple[String[1], Optional[String]]]', :options
return_type 'String'
end

def build_dn(options)
options.select { |_key, value| value }.map { |key, value| "#{key}=#{value}" }.join(', ')
options_with_values = options.filter { |_key, value| !value.nil? && value != '' }
options_with_values.map { |key, value| "#{key}=#{value}" }.join(', ')
end
end
4 changes: 4 additions & 0 deletions spec/functions/katello_build_dn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
it 'should compute dn and ignore empty values' do
is_expected.to run.with_params([['a', nil], ['b', '2']]).and_return("b=2")
end

it 'should ignore empty strings' do
is_expected.to run.with_params([['a', ''], ['b', '2']]).and_return("b=2")
end
end

0 comments on commit c815b5e

Please # to comment.