rails / marcel

Find the mime type of files, examining file, filename and declared type
Apache License 2.0
386 stars 67 forks source link

Marcel::Magic.by_magic return nil for a plain textfile #97

Closed ericproulx closed 8 months ago

ericproulx commented 10 months ago

Marcel 1.0.2

File.write('/tmp/foo.txt', "hello world")
Marcel::Magic.by_magic(File.read('/tmp/foo.txt'))
# returns nil

It's been reported in 2018 in Mimemagic and I think its the same issue when looking at tika.xml

jeremy commented 8 months ago

There are no magic bytes in a plain text file, so nil is the appropriate response.

That's what allows the type detection heuristic to fall back to provided content type headers and filename extensions as well.

If this returned text/plain for non-binary files, that'd mis-classify virtually all non-binary files.