Skip to content

Commit

Permalink
Merge pull request #2705 from dzhikvas/fix-content-type-detection
Browse files Browse the repository at this point in the history
Improve content type detection for .dotx, .ai, and others.
  • Loading branch information
mshibuya authored Dec 3, 2023
2 parents c1f500a + b7a9edc commit 20c6d75
Show file tree
Hide file tree
Showing 4 changed files with 1,710 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/carrierwave/sanitized_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,16 @@ def guessed_safe_content_type

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
Expand Down
Loading

0 comments on commit 20c6d75

Please sign in to comment.