aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--lib/rdoc/rdoc.rb8
-rw-r--r--test/rdoc/test_rdoc_rdoc.rb12
3 files changed, 22 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index b18cb7ae11..2700d4e3d7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat May 29 12:05:51 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/rdoc/rdoc.rb (RDoc#read_file_contents): take care of BOM.
+ [ruby-dev:41452]
+
Sat May 29 10:12:36 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* gc.c (GC_PROF_TIMER_STOP): regularize `marked' to suppress
diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb
index 9c39354c6c..3c08b5e4c1 100644
--- a/lib/rdoc/rdoc.rb
+++ b/lib/rdoc/rdoc.rb
@@ -406,11 +406,13 @@ The internal error was:
def read_file_contents(filename)
content = open filename, "rb" do |f| f.read end
+ utf8 = content.sub!(/\A\xef\xbb\xbf/, '')
if defined? Encoding then
if /coding[=:]\s*([^\s;]+)/i =~ content[%r"\A(?:#!.*\n)?.*\n"]
- if enc = ::Encoding.find($1)
- content.force_encoding(enc)
- end
+ enc = ::Encoding.find($1)
+ end
+ if enc ||= (Encoding::UTF_8 if utf8)
+ content.force_encoding(enc)
end
end
diff --git a/test/rdoc/test_rdoc_rdoc.rb b/test/rdoc/test_rdoc_rdoc.rb
index 866667c494..f126bfbdb2 100644
--- a/test/rdoc/test_rdoc_rdoc.rb
+++ b/test/rdoc/test_rdoc_rdoc.rb
@@ -68,6 +68,18 @@ class TestRDocRDoc < MiniTest::Unit::TestCase
assert_equal Encoding::UTF_8, contents.encoding
end
+ def test_read_file_contents_encoding_with_signature
+ skip "Encoding not implemented" unless defined? ::Encoding
+
+ @tempfile.write "\xEF\xBB\xBF""hi everybody"
+ @tempfile.flush
+
+ bug3360 = '[ruby-dev:41452]'
+ contents = @rdoc.read_file_contents @tempfile.path
+ assert_equal "hi everybody", contents, bug3360
+ assert_equal Encoding::UTF_8, contents.encoding, bug3360
+ end
+
def test_remove_unparsable
file_list = %w[
blah.class