lib/carrierwave/sanitized_file.rb in carrierwave-3.0.7 vs lib/carrierwave/sanitized_file.rb in carrierwave-3.1.0.beta

- old
+ new

@@ -319,10 +319,19 @@ type if type.start_with?('text/') || type.start_with?('application/json') end def identified_content_type with_io do |io| - Marcel::Magic.by_magic(io).try(:type) + mimetype_by_magic = Marcel::Magic.by_magic(io) + mimetype_by_path = Marcel::Magic.by_path(path) + + return nil if mimetype_by_magic.nil? + + if mimetype_by_path&.child_of?(mimetype_by_magic.type) + mimetype_by_path.type + else + mimetype_by_magic.type + end end rescue Errno::ENOENT nil end