rails / marcel

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

[Extension] Issue with `csv` extension which can be carried with `application/vnd.ms-excel` or `text/plain` content type #116

Open Mth0158 opened 1 week ago

Mth0158 commented 1 week ago

Hi,

Maintainer of active_storage_validations here 👋.

We are relying on the amazing marcel gem to do the heavy-lifting of mapping content types and extensions. However there seem to have an issue with the csv extension. Issue link => https://github.com/igorkasyanchuk/active_storage_validations/issues/291.

It seems that a .csv file can have a text/csv, application/vnd.ms-excel or text/plain content type depending on the client's OS. As mentioned by @jessie19:

TL;DR On a Windows machine with Microsoft Excel installed, CSV files may have a MIME type of application/vnd.ms-excel rather than the RFC 4180 suggested type of text/csv. Symfony, in particular, will match that MIME type with an file extension of ‘xls’. That causes issues with file validation.

source: https://christianwood.net/posts/csv-file-upload-validation/

I am unsure about what to do here, we could extend marcel with something like:

Marcel::MimeType.extend "application/vnd.ms-excel", extensions: %(csv)
Marcel::MimeType.extend "text/plain", extensions: %(csv)

But it could have side effects down the road, are you aware of this issue? @jeremy