diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/rdoc/parser.rb | 10 | ||||
-rw-r--r-- | test/rdoc/test.ja.largedoc (renamed from test/rdoc/test.ja.large.rdoc) | 0 | ||||
-rw-r--r-- | test/rdoc/test_rdoc_parser.rb | 2 |
4 files changed, 11 insertions, 6 deletions
@@ -1,3 +1,8 @@ +Fri May 4 01:31:19 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/rdoc/parser.rb (RDoc.binary?): binary read data may have + incomplete multibyte sequence. [ruby-core:44798][Bug #6393] + Wed May 2 23:55:51 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/test/unit.rb (Test::Unit::RequireFiles#non_options): expand diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index 27267f3d81..9cc1485422 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -80,14 +80,14 @@ class RDoc::Parser have_encoding = s.respond_to? :encoding - if have_encoding then - return false if s.encoding != Encoding::ASCII_8BIT and s.valid_encoding? - end - return true if s[0, 2] == Marshal.dump('')[0, 2] or s.index("\x00") if have_encoding then - s.force_encoding Encoding.default_external + mode = "r" + s.sub!(/\A#!.*\n/, '') # assume shebang line isn't longer than 1024. + encoding = s[/^\s*\#\s*(?:-\*-\s*)?(?:en)?coding:\s*\([^\s;]+?\)(?:-\*-)?/, 1] + mode = "r:#{encoding}" if encoding + s = File.open(file, mode) {|f| f.gets(nil, 1024)} not s.valid_encoding? else diff --git a/test/rdoc/test.ja.large.rdoc b/test/rdoc/test.ja.largedoc index a9c6c4691c..a9c6c4691c 100644 --- a/test/rdoc/test.ja.large.rdoc +++ b/test/rdoc/test.ja.largedoc diff --git a/test/rdoc/test_rdoc_parser.rb b/test/rdoc/test_rdoc_parser.rb index e0629e37b6..37d3b67323 100644 --- a/test/rdoc/test_rdoc_parser.rb +++ b/test/rdoc/test_rdoc_parser.rb @@ -29,7 +29,7 @@ class TestRDocParser < MiniTest::Unit::TestCase end def test_class_binary_large_japanese_rdoc - file_name = File.expand_path '../test.ja.large.rdoc', __FILE__ + file_name = File.expand_path '../test.ja.largedoc', __FILE__ assert !@RP.binary?(file_name) end |