diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/rdoc/parser.rb | 7 |
2 files changed, 9 insertions, 5 deletions
@@ -1,3 +1,10 @@ +Fri Apr 2 14:12:24 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/rdoc/parser.rb (RDoc::Parser.binary?): blksize may be nil + and is irrelevant to whether a file is binary. TAB and newlines + would be usually considered to be included in text data. + reapplied r23071 and r24297. + Fri Apr 2 13:59:17 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/rdoc/ri/paths.rb (RDoc::RI::Paths): Gem::Enable has been diff --git a/lib/rdoc/parser.rb b/lib/rdoc/parser.rb index e1b264bffa..a5c7de663f 100644 --- a/lib/rdoc/parser.rb +++ b/lib/rdoc/parser.rb @@ -67,7 +67,7 @@ class RDoc::Parser # content that an RDoc parser shouldn't try to consume. def self.binary?(file) - s = File.read(file, File.stat(file).blksize || 1024) || "" + s = File.read(file, 1024) or return false if s[0, 2] == Marshal.dump('')[0, 2] then true @@ -76,10 +76,7 @@ class RDoc::Parser elsif s.scan(/<%|%>/).length >= 4 then true else - # From ptools under the Artistic License 2.0, (c) Daniel Berger. - s = s.split(//) - - ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30 + s.count("^ -~\t\r\n").fdiv(s.size) > 0.3 || s.index("\x00") end end |