diff --git a/lib/simplecov/lines_classifier.rb b/lib/simplecov/lines_classifier.rb index 0aa9ff9e..e8e7de50 100644 --- a/lib/simplecov/lines_classifier.rb +++ b/lib/simplecov/lines_classifier.rb @@ -16,21 +16,30 @@ def self.no_cov_line @no_cov_line ||= /^(\s*)#(\s*)(\:#{SimpleCov.nocov_token}\:)/ end + def self.no_cov_line?(line) + line =~ no_cov_line + rescue ArgumentError + # E.g., line contains an invalid byte sequence in UTF-8 + false + end + + def self.whitespace_line?(line) + line =~ WHITESPACE_OR_COMMENT_LINE + rescue ArgumentError + # E.g., line contains an invalid byte sequence in UTF-8 + false + end + def classify(lines) skipping = false lines.map do |line| - begin - if line =~ self.class.no_cov_line - skipping = !skipping - NOT_RELEVANT - elsif skipping || line =~ WHITESPACE_OR_COMMENT_LINE - NOT_RELEVANT - else - RELEVANT - end - rescue ArgumentError - # E.g., line contains an invalid byte sequence in UTF-8 + if self.class.no_cov_line?(line) + skipping = !skipping + NOT_RELEVANT + elsif skipping || self.class.whitespace_line?(line) + NOT_RELEVANT + else RELEVANT end end diff --git a/lib/simplecov/source_file.rb b/lib/simplecov/source_file.rb index 3465c360..6b952a72 100644 --- a/lib/simplecov/source_file.rb +++ b/lib/simplecov/source_file.rb @@ -182,7 +182,7 @@ def process_skipped_lines(lines) skipping = false lines.each do |line| - if line.src =~ SimpleCov::LinesClassifier.no_cov_line + if SimpleCov::LinesClassifier.no_cov_line?(line.src) skipping = !skipping line.skipped! elsif skipping