Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash on invalid UTF-8 byte sequences. #664

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ unreleased

* (breaking) Stop handling string filters as regular expressions, use the dedicated regex filter if you need that behaviour. See [#616](https://github.com/colszowka/simplecov/pull/616) (thanks @yujinakayama)
* Avoid overwriting the last coverage results on unsuccessful test runs. See [#625](https://github.com/colszowka/simplecov/pull/625) (thanks @thomas07vt)
* Don't crash on invalid UTF-8 byte sequences.

0.15.1 (2017-09-11) ([changes](https://github.com/colszowka/simplecov/compare/v0.15.0...v0.15.1))
=======
Expand Down
17 changes: 11 additions & 6 deletions lib/simplecov/lines_classifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ def classify(lines)
skipping = false

lines.map do |line|
if line =~ self.class.no_cov_line
skipping = !skipping
NOT_RELEVANT
elsif skipping || line =~ WHITESPACE_OR_COMMENT_LINE
NOT_RELEVANT
else
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good explanatory why comment!

RELEVANT
end
end
Expand Down
9 changes: 9 additions & 0 deletions spec/lines_classifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
expect(classified_lines.length).to eq 7
expect(classified_lines).to all be_relevant
end

it "determines invalid UTF-8 byte sequences as relevant" do
classified_lines = subject.classify [
"bytes = \"\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n\"",
]

expect(classified_lines.length).to eq 1
expect(classified_lines).to all be_relevant
end
end

describe "not-relevant lines" do
Expand Down