summaryrefslogtreecommitdiff
path: root/lib/rdoc/rdoc.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-29 03:05:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-29 03:05:55 +0000
commit8e9f30887c80776fa2960d684fe3d43b93dbc1c4 (patch)
tree35cd65ab2cab41d321e5dc672db2c4aae57f7ade /lib/rdoc/rdoc.rb
parent790abc5991837b59e0682388c318c32cb1628425 (diff)
* lib/rdoc/rdoc.rb (RDoc#read_file_contents): take care of BOM.
[ruby-dev:41452] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28062 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/rdoc.rb')
-rw-r--r--lib/rdoc/rdoc.rb8
1 files changed, 5 insertions, 3 deletions
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