mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Consider webp a supported image format for upload (#9015)
* Also fixes an issue where if webp was a downloaded hotlinked image and then secure + sent in an email, it was not being redacted because webp was not a supported media format in FileHelper * Webp originally removed as an image format in https://github.com/discourse/discourse/pull/6377 and there was a spec to make sure a .bin webp file did not get renamed from its type to webp. However we want to support webp images now to make sure they are properly redacted if secure media is on, so change the example in the spec to use tiff, another banned format, instead
This commit is contained in:
@@ -194,7 +194,7 @@ export function authorizesOneOrMoreImageExtensions(staff) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isImage(path) {
|
export function isImage(path) {
|
||||||
return /\.(png|jpe?g|gif|svg|ico)$/i.test(path);
|
return /\.(png|webp|jpe?g|gif|svg|ico)$/i.test(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isVideo(path) {
|
export function isVideo(path) {
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ class FileHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.supported_images
|
def self.supported_images
|
||||||
@@supported_images ||= Set.new %w{jpg jpeg png gif svg ico}
|
@@supported_images ||= Set.new %w{jpg jpeg png gif svg ico webp}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.supported_audio
|
def self.supported_audio
|
||||||
|
|||||||
BIN
spec/fixtures/images/tiff_as.bin
vendored
Normal file
BIN
spec/fixtures/images/tiff_as.bin
vendored
Normal file
Binary file not shown.
@@ -79,12 +79,12 @@ RSpec.describe UploadCreator do
|
|||||||
expect(upload.original_filename).to eq('png_as.png')
|
expect(upload.original_filename).to eq('png_as.png')
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'for webp format' do
|
describe 'for tiff format' do
|
||||||
before do
|
before do
|
||||||
SiteSetting.authorized_extensions = '.webp|.bin'
|
SiteSetting.authorized_extensions = '.tiff|.bin'
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:filename) { "webp_as.bin" }
|
let(:filename) { "tiff_as.bin" }
|
||||||
let(:file) { file_from_fixtures(filename) }
|
let(:file) { file_from_fixtures(filename) }
|
||||||
|
|
||||||
it 'should not correct the coerce filename' do
|
it 'should not correct the coerce filename' do
|
||||||
@@ -96,7 +96,7 @@ RSpec.describe UploadCreator do
|
|||||||
|
|
||||||
expect(upload.extension).to eq('bin')
|
expect(upload.extension).to eq('bin')
|
||||||
expect(File.extname(upload.url)).to eq('.bin')
|
expect(File.extname(upload.url)).to eq('.bin')
|
||||||
expect(upload.original_filename).to eq('webp_as.bin')
|
expect(upload.original_filename).to eq('tiff_as.bin')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ QUnit.test("allows valid uploads to go through", assert => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("isImage", assert => {
|
QUnit.test("isImage", assert => {
|
||||||
["png", "jpg", "jpeg", "gif", "ico"].forEach(extension => {
|
["png", "webp", "jpg", "jpeg", "gif", "ico"].forEach(extension => {
|
||||||
var image = "image." + extension;
|
var image = "image." + extension;
|
||||||
assert.ok(isImage(image), image + " is recognized as an image");
|
assert.ok(isImage(image), image + " is recognized as an image");
|
||||||
assert.ok(
|
assert.ok(
|
||||||
|
|||||||
Reference in New Issue
Block a user