diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-02 05:12:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-04-02 05:12:31 +0000 |
commit | 06adf90ab66829cc24b15ddb7be5e12a60a3141e (patch) | |
tree | bf8f69d6ad934ac1a9f6f7d47c49c56d844f67f7 | |
parent | 5bdee08c1e48c0fa731cae9469e09355c0e576f4 (diff) |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-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 <[email protected]> + + * 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 <[email protected]> * 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 |