Commit fe704eb1 authored by Kev's avatar Kev Committed by Heinrich Lee Yu

Render WebP attachments as image by default

This adds the .webp file extension to the list of safe image extensions
in the file type detection. It allows webp-images to be uploaded to
issues and comments which then get embeded as images instead of
attachments (see [gitlab-org/gitlab#296600](3)). It also allows uploading
of designs in the webp format. WebP is supported in all browsers that
GitLab supports except Safari <= macOS 10
(see [caniuse][1], [suppported browsers][2]).

[1]: https://caniuse.com/webp
[2]: https://docs.gitlab.com/ee/install/requirements.html#supported-web-browsers
[3]: https://gitlab.com/gitlab-org/gitlab/-/issues/296600
parent 036539ce
---
title: Render WebP attachments as image by default
merge_request: 51088
author: Kev @KevSlashNull
type: changed
...@@ -46,7 +46,7 @@ If the requirements are not met, the **Designs** tab displays a message to the u ...@@ -46,7 +46,7 @@ If the requirements are not met, the **Designs** tab displays a message to the u
## Supported files ## Supported files
Files uploaded must have a file extension of either `png`, `jpg`, `jpeg`, Files uploaded must have a file extension of either `png`, `jpg`, `jpeg`,
`gif`, `bmp`, `tiff`, `ico`, or `svg`. `gif`, `bmp`, `tiff`, `ico`, `webp`, or `svg`.
Support for [PDF](https://gitlab.com/gitlab-org/gitlab/issues/32811) is planned for a future release. Support for [PDF](https://gitlab.com/gitlab-org/gitlab/issues/32811) is planned for a future release.
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
# `Content-Type` and `Content-Disposition` to the one we get from the detection. # `Content-Type` and `Content-Disposition` to the one we get from the detection.
module Gitlab module Gitlab
module FileTypeDetection module FileTypeDetection
SAFE_IMAGE_EXT = %w[png jpg jpeg gif bmp tiff ico].freeze SAFE_IMAGE_EXT = %w[png jpg jpeg gif bmp tiff ico webp].freeze
SAFE_IMAGE_FOR_SCALING_EXT = %w[png jpg jpeg].freeze SAFE_IMAGE_FOR_SCALING_EXT = %w[png jpg jpeg].freeze
PDF_EXT = 'pdf' PDF_EXT = 'pdf'
......
...@@ -410,7 +410,7 @@ RSpec.describe Group do ...@@ -410,7 +410,7 @@ RSpec.describe Group do
it "is false if avatar is html page" do it "is false if avatar is html page" do
group.update_attribute(:avatar, 'uploads/avatar.html') group.update_attribute(:avatar, 'uploads/avatar.html')
expect(group.avatar_type).to eq(["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico"]) expect(group.avatar_type).to eq(["file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico, webp"])
end end
end end
......
...@@ -1256,7 +1256,7 @@ RSpec.describe Project, factory_default: :keep do ...@@ -1256,7 +1256,7 @@ RSpec.describe Project, factory_default: :keep do
it 'is false if avatar is html page' do it 'is false if avatar is html page' do
project.update_attribute(:avatar, 'uploads/avatar.html') project.update_attribute(:avatar, 'uploads/avatar.html')
expect(project.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico']) expect(project.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico, webp'])
end end
end end
......
...@@ -2477,7 +2477,7 @@ RSpec.describe User do ...@@ -2477,7 +2477,7 @@ RSpec.describe User do
it 'is false if avatar is html page' do it 'is false if avatar is html page' do
user.update_attribute(:avatar, 'uploads/avatar.html') user.update_attribute(:avatar, 'uploads/avatar.html')
expect(user.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico']) expect(user.avatar_type).to eq(['file format is not supported. Please try one of the following supported formats: png, jpg, jpeg, gif, bmp, tiff, ico, webp'])
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment