diff --git a/lib/signature_detection.rb b/lib/signature_detection.rb index 930087b9e..1ce20ab24 100644 --- a/lib/signature_detection.rb +++ b/lib/signature_detection.rb @@ -38,6 +38,8 @@ returns .map { |head, tail| [head + 1, tail - 1] } .find { |head, tail| tail > head + 4 } + next if sig_range.nil? + # Take up to 10 lines from this "gap" (i.e., the common substring) match_content = diff_lines[sig_range.first..sig_range.last] .map { |l| l.sub(/^./, '') } diff --git a/spec/lib/signature_detection_spec.rb b/spec/lib/signature_detection_spec.rb index db33664d1..b6d592a2a 100644 --- a/spec/lib/signature_detection_spec.rb +++ b/spec/lib/signature_detection_spec.rb @@ -90,6 +90,21 @@ RSpec.describe SignatureDetection do end end end + + context 'when input messages do not share 5-line common substrings' do + let(:messages) do + Array.new(2) { { content: <<~RAW, content_type: 'text/plain' } } + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Ut ut tincidunt nunc. Sed mattis aliquam tellus sit amet lacinia. + Mauris fermentum dictum aliquet. + Nam ex risus, gravida et ornare ut, mollis non sapien. + RAW + end + + it 'doesn’t break' do + expect { described_class.find_signature(messages) }.not_to raise_error + end + end end describe '.find_signature_line' do