Skip to content

Commit

Permalink
Fix encoding problem
Browse files Browse the repository at this point in the history
incompatible character encodings: ASCII-8BIT and UTF-8

Taken from simplecov-ruby/simplecov#866
  • Loading branch information
Jean-Michel Garnier committed Sep 27, 2021
1 parent c8e9e46 commit b442606
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/reverse_coverage/formatters/html/formatter.rb
Expand Up @@ -58,7 +58,27 @@ def formatted_source_file(source_file)
end

def readfile(source_file)
File.open(filename(source_file), "rb", &:readlines)
load_source(filename(source_file))
end

def load_source(file_name)
lines = []
# The default encoding is UTF-8
File.open(file_name, "rb:UTF-8") do |file|
line = file.gets

# Check for shbang
if /\A#!/.match?(line)
lines << line
line = file.gets
end
return lines unless line

check_magic_comment(file, line)
lines.concat([line], file.readlines)
end

lines
end

def grouped(files)
Expand Down

0 comments on commit b442606

Please sign in to comment.