Permalink
Browse files

Bug #28391

  • Loading branch information...
1 parent 8d6dd97 commit 5177623b2731af6c31d7041f609048d8265a0f37 @drbrain drbrain committed Aug 11, 2010
Showing with 29 additions and 9 deletions.
  1. +3 −0 History.txt
  2. +11 −0 lib/rdoc/parser.rb
  3. +1 −9 lib/rdoc/rdoc.rb
  4. +2 −0 test/test.ja.rdoc
  5. +12 −0 test/test_rdoc_parser.rb
View
@@ -3,6 +3,9 @@
* Minor Enhancements
* Support rb_singleton_class(). Reported by Jeremy Evans.
+* Bug Fixes
+ * Tread non-ASCII RDoc files as text. Bug #28391 by Kouhei Sutou.
+
=== 2.5.9 / 2010-07-06
* Bug Fixes
View
@@ -62,12 +62,23 @@ def self.alias_extension(old_ext, new_ext)
true
end
+ def self.set_encoding(string)
+ if defined? Encoding then
+ if /coding[=:]\s*([^\s;]+)/i =~ string[%r"\A(?:#!.*\n)?.*\n"]
+ if enc = ::Encoding.find($1)
+ string.force_encoding(enc)
+ end
+ end
+ end
+ end
+
##
# Determines if the file is a "binary" file which basically means it has
# content that an RDoc parser shouldn't try to consume.
def self.binary?(file)
s = File.read(file, 1024) or return false
+ set_encoding(s)
if s[0, 2] == Marshal.dump('')[0, 2] then
true
View
@@ -405,15 +405,7 @@ def document(argv)
def read_file_contents(filename)
content = open filename, "rb" do |f| f.read end
-
- if defined? Encoding then
- if /coding[=:]\s*([^\s;]+)/i =~ content[%r"\A(?:#!.*\n)?.*\n"]
- if enc = ::Encoding.find($1)
- content.force_encoding(enc)
- end
- end
- end
-
+ RDoc::Parser.set_encoding(content)
content
rescue Errno::EISDIR, Errno::ENOENT
nil
View
@@ -1,3 +1,5 @@
+# -*- coding: utf-8 -*-
+
こんにちは!
初めまして。アーロンと申します。
View
@@ -42,6 +42,18 @@ def test_class_binary_eh_marshal
File.unlink marshal
end
+ def test_class_binary_japanese_text
+ file_name = File.expand_path '../test.ja.txt', __FILE__
+ assert @RP.binary?(file_name)
+ end
+
+ def test_class_binary_japanese_rdoc
+ skip "Encoding not implemented" unless defined? ::Encoding
+
+ file_name = File.expand_path '../test.ja.rdoc', __FILE__
+ assert !@RP.binary?(file_name)
+ end
+
def test_class_can_parse
assert_equal @RP.can_parse(__FILE__), @RP::Ruby

0 comments on commit 5177623

Please sign in to comment.