diff --git a/middleman-core/lib/middleman-core/util.rb b/middleman-core/lib/middleman-core/util.rb index 46854994..0444be7a 100644 --- a/middleman-core/lib/middleman-core/util.rb +++ b/middleman-core/lib/middleman-core/util.rb @@ -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, 4096) || '' + 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')