diff --git a/app/models/html_variant.rb b/app/models/html_variant.rb index 0ee6a86ee..0d383fd1d 100644 --- a/app/models/html_variant.rb +++ b/app/models/html_variant.rb @@ -75,6 +75,6 @@ class HtmlVariant < ApplicationRecord end def allowed_image_host?(src) - src.start_with?("https://res.cloudinary.com/") + src.start_with?("https://res.cloudinary.com/") || src.start_with?(Images::Optimizer.get_imgproxy_endpoint) end end diff --git a/app/services/images/optimizer.rb b/app/services/images/optimizer.rb index 9ef1ae1aa..c06ace3d8 100644 --- a/app/services/images/optimizer.rb +++ b/app/services/images/optimizer.rb @@ -66,7 +66,7 @@ module Images # On other environments, rely on ApplicationConfig for a # more flexible configuration # ie. default imgproxy endpoint is localhost:8080 - ApplicationConfig["IMGPROXY_ENDPOINT"] + ApplicationConfig["IMGPROXY_ENDPOINT"] || "http://localhost:8080" end end end diff --git a/spec/models/html_variant_spec.rb b/spec/models/html_variant_spec.rb index 0a4f605be..00be54dad 100644 --- a/spec/models/html_variant_spec.rb +++ b/spec/models/html_variant_spec.rb @@ -55,4 +55,19 @@ RSpec.describe HtmlVariant, type: :model do cloudinary_string = "/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_420/https://devimages.com/image.jpg" expect(html_variant.html).to include(cloudinary_string) end + + it "does not add prefix if it already starts with cloudinary" do + allow(Images::Optimizer).to receive(:call) + html = %() + html_variant.update(approved: false, html: html) + expect(Images::Optimizer).not_to have_received(:call) + end + + it "does not add prefix if already on site root" do + allow(Images::Optimizer).to receive(:call) + html = "" + html_variant.update(approved: false, html: html) + html_variant.save + expect(Images::Optimizer).not_to have_received(:call) + end end