Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Show large image placeholder for image onebox #21237

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/cooked_post_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ def post_process_images
end

def 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_h
normalized_src =
PostHotlinkedMedia.normalize_src(img["src"] || img[PrettyText::BLOCKED_HOTLINKED_SRC_ATTR])
Expand All @@ -393,15 +395,15 @@ def process_hotlinked_image(img)
still_an_image = true

if info&.too_large?
if img.ancestors(".onebox, .onebox-body").blank?
if !onebox || onebox.element_children.size == 1
add_large_image_placeholder!(img)
else
img.remove
end

still_an_image = false
elsif info&.download_failed?
if img.ancestors(".onebox, .onebox-body").blank?
if !onebox || onebox.element_children.size == 1
add_broken_image_placeholder!(img)
else
img.remove
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/cooked_post_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1152,13 +1152,13 @@

it "replaces large image placeholder" do
SiteSetting.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>
HTML

post = Fabricate(:post, raw: url)

Expand Down