2

Active Storage: deprecate invalid default content types by ghiculescu · Pull Req...

 2 years ago
source link: https://github.com/rails/rails/pull/42227
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Member

ghiculescu commented on May 14

edited

This PR deprecates some invalid content types in the default content types supported by Active Storage. In Rails 7.1 those content types will be removed from Active Storage defaults, but you can add them in through an initialiser if you still want to use them.

Changes in this PR:

The following content types will now warn when used:

  • Remove image/jpg and image/pjpeg (they were never recognised by mini_mime, Active Storage representers treat them as a PNG)
  • text/javascript (should be application/javascript)
  • image/bmp (should be image/x-bmp)

You can set config.active_storage.silence_invalid_content_types_warning = true to dismiss the warning.

You can see the list of recognised content types here: https://github.com/discourse/mini_mime/blob/master/lib/db/content_type_mime.db

Why this change?

#42225 identified that some of the content types used as defaults by Active Storage aren't recognized by mini_mime. This means that in practice code like this will crash or not function correctly. In this example, a file with content_type image/jpg is treated as a PNG by the representer, since image/jpg isn't a valid content type according to mini_mime.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK