summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-03 16:31:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-05-03 16:31:25 +0000
commit1348e3b9ac686433047b30689159f0e5bc3279dc (patch)
tree6c815667448c8d2ba11661364c567c5433c1a8c6
parent19be9a8d80bb170b9189c997af90329e7e7af92c (diff)
rdoc: non-binary multibyte
* lib/rdoc/parser.rb (RDoc.binary?): binary read data may have incomplete multibyte sequence. [ruby-core:44798][Bug #6393] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35531 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--lib/rdoc/parser.rb10
-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.rb2
4 files changed, 11 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 9128cb66ae..12450bcd19 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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