summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-02 05:12:31 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-02 05:12:31 +0000
commit06adf90ab66829cc24b15ddb7be5e12a60a3141e (patch)
treebf8f69d6ad934ac1a9f6f7d47c49c56d844f67f7 /lib
parent5bdee08c1e48c0fa731cae9469e09355c0e576f4 (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
Diffstat (limited to 'lib')
-rw-r--r--lib/rdoc/parser.rb7
1 files changed, 2 insertions, 5 deletions
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