Просмотр исходного кода

Fixes #2740 - Signature detection fails if no signature range could be found.

Ryan Lue 5 лет назад
Родитель
Сommit
3107d684b5
2 измененных файлов с 17 добавлено и 0 удалено
  1. 2 0
      lib/signature_detection.rb
  2. 15 0
      spec/lib/signature_detection_spec.rb

+ 2 - 0
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(/^./, '') }

+ 15 - 0
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