diff --git a/lib/simplecov/source_file.rb b/lib/simplecov/source_file.rb index 73d90cc7..75a9696e 100644 --- a/lib/simplecov/source_file.rb +++ b/lib/simplecov/source_file.rb @@ -79,7 +79,7 @@ def status def initialize(filename, coverage) @filename, @coverage = filename, coverage - File.open(filename, "r:UTF-8") {|f| @src = f.readlines } + File.open(filename, "r:UTF-8:UTF-8") {|f| @src = f.readlines } end # Returns all source lines for this file as instances of SimpleCov::SourceFile::Line, diff --git a/test/test_source_file.rb b/test/test_source_file.rb index 3474a576..16343fc3 100644 --- a/test/test_source_file.rb +++ b/test/test_source_file.rb @@ -86,6 +86,20 @@ class TestSourceFile < Test::Unit::TestCase assert_nothing_raised do source_file.process_skipped_lines! end + + should "handle utf-8 encoded source files when the default_internal encoding is binary" do + original_internal_encoding = Encoding.default_internal + Encoding.default_internal = "BINARY" + begin + source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1]) + ensure + Encoding.default_internal = original_internal_encoding + end + + assert_nothing_raised do + source_file.process_skipped_lines! + end + end end end end if SimpleCov.usable?