From d10e9a6c1d01a49d9478bb13773328ef4c7aab47 Mon Sep 17 00:00:00 2001 From: Rafael dos Santos Silva Date: Thu, 24 Aug 2023 16:44:06 -0300 Subject: [PATCH] FEATURE: Onebox and Download for WEBP and AVIF (#23235) This adds support for oneboxing WEBP and AVIF images in posts and fixing oneboxing fixes download remote images for those formats too. Reported in https://meta.discourse.org/t/-/276433?u=falco --- lib/onebox/engine/image_onebox.rb | 4 ++-- spec/lib/onebox/engine/image_onebox_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/onebox/engine/image_onebox.rb b/lib/onebox/engine/image_onebox.rb index 2b6e08ac923..28d446ca5ff 100644 --- a/lib/onebox/engine/image_onebox.rb +++ b/lib/onebox/engine/image_onebox.rb @@ -5,8 +5,8 @@ module Onebox class ImageOnebox include Engine - matches_content_type(%r{^image/(png|jpg|jpeg|gif|bmp|tif|tiff)$}) - matches_regexp(%r{^(https?:)?//.+\.(png|jpg|jpeg|gif|bmp|tif|tiff)(\?.*)?$}i) + matches_content_type(%r{^image/(png|jpg|jpeg|gif|bmp|tif|tiff|webp|avif)$}) + matches_regexp(%r{^(https?:)?//.+\.(png|jpg|jpeg|gif|bmp|tif|tiff|webp|avif)(\?.*)?$}i) def always_https? AllowlistedGenericOnebox.host_matches(uri, AllowlistedGenericOnebox.https_hosts) diff --git a/spec/lib/onebox/engine/image_onebox_spec.rb b/spec/lib/onebox/engine/image_onebox_spec.rb index b3889bd528f..0b77ca280e0 100644 --- a/spec/lib/onebox/engine/image_onebox_spec.rb +++ b/spec/lib/onebox/engine/image_onebox_spec.rb @@ -39,6 +39,18 @@ RSpec.describe Onebox::Engine::ImageOnebox do ).to match(/