From b9d689f34f23f6a48f861b1ab2678025cd66e745 Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Mon, 4 Feb 2013 15:42:05 -0600 Subject: [PATCH] Compatability with BINARY internal encoding - Specify the default_internal encoding as UTF-8 when reading source files. This fixes Issue #127. --- lib/simplecov/source_file.rb | 2 +- test/test_source_file.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 64cdd62a..7db225d0 100644 --- a/test/test_source_file.rb +++ b/test/test_source_file.rb @@ -88,6 +88,20 @@ class TestSourceFile < Test::Unit::TestCase source_file.process_skipped_lines! end 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