Skip to content

Commit c05b989

Browse files
committed
(GH-1158) Fix for dport/sport comparisons
Values where being compared incorrectly when passed as integers or with multiple negated array values.
1 parent a301fff commit c05b989

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

lib/puppet/provider/firewall/firewall.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,19 +436,25 @@ def insync?(context, _name, property_name, is_hash, should_hash)
436436
is = [is] unless is.is_a?(Array)
437437
should = [should] unless should.is_a?(Array)
438438

439-
# If first value includes a negation, retrieve it and set as it's own value
440-
if is[0].start_with?('!')
441-
is.append('!')
442-
is[0] = is[0].gsub(%r{^!\s?}, '')
439+
# Ensure values are sorted
440+
# Ensure any negation includes only the first value
441+
is_negated = true if %r{^!\s}.match?(is[0].to_s)
442+
is.each_with_index do |_value, _index|
443+
is = is.map { |value| value.to_s.tr('! ', '') }.sort
443444
end
444-
if should[0].start_with?('!')
445-
should.append('!')
446-
should[0] = should[0].gsub(%r{^!\s?}, '')
445+
is[0] = ['!', is[0]].join(' ') if is_negated
446+
447+
should_negated = true if %r{^!\s}.match?(should[0].to_s)
448+
should.each_with_index do |_value, _index|
449+
should = should.map { |value| value.to_s.tr('! ', '') }.sort
450+
# Range can be passed as `-` but will always be set/returned as `:`
451+
should = should.map { |value| value.to_s.tr('-', ':') }.sort
447452
end
453+
should[0] = ['!', should[0]].join(' ') if should_negated
448454

449455
# Range can be passed as `-` but will always be set/returned as `:`
450456
# Ensure values are sorted
451-
is.sort == should.map { |port| port.to_s.tr('-', ':') }.sort
457+
is == should
452458
when :string_hex
453459
# Compare the values with any whitespace removed
454460
is = is_hash[property_name].to_s.gsub(%r{\s+}, '')

0 commit comments

Comments
 (0)