A platform for community discussion. Free, open, simple.
FIX: Show large image placeholder for image onebox (#21237)
Bianca Nenciu024b8b26402e
diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rbindex 8415100965a..0e6e15986e7 100644--- a/lib/cooked_post_processor.rb+++ b/lib/cooked_post_processor.rb@@ -385,6 +385,8 @@ class CookedPostProcessorenddef process_hotlinked_image(img)+ onebox = img.ancestors(".onebox, .onebox-body").first+@hotlinked_map ||= @post.post_hotlinked_media.preload(:upload).map { |r| [r.url, r] }.to_hnormalized_src =PostHotlinkedMedia.normalize_src(img["src"] || img[PrettyText::BLOCKED_HOTLINKED_SRC_ATTR])@@ -393,7 +395,7 @@ class CookedPostProcessorstill_an_image = trueif info&.too_large?- if img.ancestors(".onebox, .onebox-body").blank?+ if !onebox || onebox.element_children.size == 1add_large_image_placeholder!(img)elseimg.remove@@ -401,7 +403,7 @@ class CookedPostProcessorstill_an_image = falseelsif info&.download_failed?- if img.ancestors(".onebox, .onebox-body").blank?+ if !onebox || onebox.element_children.size == 1add_broken_image_placeholder!(img)elseimg.removediff --git a/spec/lib/cooked_post_processor_spec.rb b/spec/lib/cooked_post_processor_spec.rbindex 566b9726cea..df42d360cb8 100644--- a/spec/lib/cooked_post_processor_spec.rb+++ b/spec/lib/cooked_post_processor_spec.rb@@ -1152,13 +1152,13 @@ RSpec.describe CookedPostProcessor doit "replaces large image placeholder" doSiteSetting.max_image_size_kb = 4096- url = "https://image.com/my-avatar"- image_url = "https://image.com/avatar.png"+ url = "https://image.com/avatar.png"- Oneboxer- .stubs(:onebox)- .with(url, anything)- .returns("<img class='onebox' src='#{image_url}' />")+ Oneboxer.stubs(:onebox).with(url, anything).returns <<~HTML+ <a href="#{url}" target="_blank" rel="noopener" class="onebox">+ <img class='onebox' src='#{url}' />+ </a>+ HTMLpost = Fabricate(:post, raw: url)