@@ -416,28 +416,34 @@ def insync?(context, _name, property_name, is_hash, should_hash)
416416 when :dport , :sport , :state , :ctstate , :ctstatus
417417 is = is_hash [ property_name ]
418418 should = should_hash [ property_name ]
419+ ports = [ :dport , :sport ]
420+
421+ if is . is_a? ( Array ) && should . is_a? ( Array )
422+ # Ensure values are sorted
423+ # Ensure any negation includes only the first value
424+ is_negated = true if %r{^!\s } . match? ( is [ 0 ] . to_s )
425+ is . each_with_index do |_value , _index |
426+ is = is . map { |value | value . to_s . tr ( '! ' , '' ) } . sort
427+ end
428+ is [ 0 ] = [ '!' , is [ 0 ] ] . join ( ' ' ) if is_negated
419429
420- # Unique logic is only needed when both values are arrays
421- return nil unless is . is_a? ( Array ) && should . is_a? ( Array )
422-
423- # Ensure values are sorted
424- # Ensure any negation includes only the first value
425- is_negated = true if %r{^!\s } . match? ( is [ 0 ] . to_s )
426- is . each_with_index do |_value , _index |
427- is = is . map { |value | value . to_s . tr ( '! ' , '' ) } . sort
428- end
429- is [ 0 ] = [ '!' , is [ 0 ] ] . join ( ' ' ) if is_negated
430+ should_negated = true if %r{^!\s } . match? ( should [ 0 ] . to_s )
431+ should . each_with_index do |_value , _index |
432+ should = should . map { |value | value . to_s . tr ( '! ' , '' ) } . sort
433+ # Port range can be passed as `-` but will always be set/returned as `:`
434+ should = should . map { |value | value . to_s . tr ( '-' , ':' ) } . sort if ports . include? ( property_name )
435+ end
436+ should [ 0 ] = [ '!' , should [ 0 ] ] . join ( ' ' ) if should_negated
430437
431- should_negated = true if %r{^!\s } . match? ( should [ 0 ] . to_s )
432- should . each_with_index do |_value , _index |
433- should = should . map { |value | value . to_s . tr ( '! ' , '' ) } . sort
438+ is == should
439+ elsif is . is_a? ( String ) && should . is_a? ( String )
434440 # Port range can be passed as `-` but will always be set/returned as `:`
435- ports = [ :dport , :sport ]
436- should = should . map { |value | value . to_s . tr ( '-' , ':' ) } . sort if ports . include? ( property_name )
437- end
438- should [ 0 ] = [ '!' , should [ 0 ] ] . join ( ' ' ) if should_negated
441+ should = should . tr ( '-' , ':' ) if ports . include? ( property_name )
439442
440- is == should
443+ is == should
444+ else
445+ return nil
446+ end
441447 when :string_hex
442448 # Compare the values with any whitespace removed
443449 is = is_hash [ property_name ] . to_s . gsub ( %r{\s +} , '' )
0 commit comments