From 65dc47adb40d840ff9908e1c17c8c301c3c18883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 18 Oct 2017 01:50:23 +0200 Subject: [PATCH] FIX: prevent infinite 'pull_hotlinked_images' jobs when a oneboxed image has a different scheme --- lib/cooked_post_processor.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 9af9220dad5..5e005549ecf 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -110,8 +110,16 @@ class CookedPostProcessor end def oneboxed_image_uploads - urls = oneboxed_images.map { |img| img["src"] } - Upload.where(origin: urls) + urls = Set.new + + oneboxed_images.each do |img| + url = img["src"].sub(/^https?:/i, "") + urls << url + urls << "http:#{url}" + urls << "https:#{url}" + end + + Upload.where(origin: urls.to_a) end def limit_size!(img) @@ -323,7 +331,8 @@ class CookedPostProcessor uploads = oneboxed_image_uploads.select(:url, :origin) oneboxed_images.each do |img| - upload = uploads.detect { |u| u.origin == img["src"] } + url = img["src"].sub(/^https?:/i, "") + upload = uploads.find { |u| u.origin.sub(/^https?:/i, "") == url } next unless upload.present? img["src"] = upload.url # make sure we grab dimensions for oneboxed images