Fix huge files regression (for undetected mime)

Note that binary_bytes is an array of bytes that never never appears in text. Array taken from encoding.c source from 'file' utility (http://www.darwinsys.com/file/).
This commit is contained in:
Egor 2013-02-02 00:26:58 +04:00
parent 81acdca5f9
commit 83c8f9a2ce

View file

@ -24,7 +24,14 @@ module Middleman
ext = ".#{ext}" unless ext.to_s[0] == ?.
mime = ::Rack::Mime.mime_type(ext, nil)
return false unless mime
unless mime
binary_bytes = [0, 1, 2, 3, 4, 5, 6, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31]
s = File.read(filename, File.stat(filename).blksize) || ''
s.each_byte do |c|
return true if binary_bytes.include?(c)
end
return false
end
return false if mime.start_with?('text/')
return false if mime.include?('xml')
return false if mime.include?('json')