FIX: Display large/broken image placeholders for image oneboxes
This commit is contained in:
parent
83bf641292
commit
c499872597
|
@ -177,8 +177,6 @@ class CookedPostProcessor
|
|||
@doc.css("img[src^='data']") -
|
||||
# minus emojis
|
||||
@doc.css("img.emoji") -
|
||||
# minus oneboxed images
|
||||
oneboxed_images -
|
||||
# minus images inside quotes
|
||||
@doc.css(".quote img")
|
||||
end
|
||||
|
@ -410,9 +408,12 @@ class CookedPostProcessor
|
|||
next if img["src"].blank?
|
||||
|
||||
src = img["src"].sub(/^https?:/i, "")
|
||||
parent = img.parent
|
||||
img_classes = (img["class"] || "").split(" ")
|
||||
link_classes = ((parent&.name == "a" && parent["class"]) || "").split(" ")
|
||||
|
||||
if large_images.include?(src) || broken_images.include?(src)
|
||||
img.remove
|
||||
img.remove unless img_classes.include?("onebox") || link_classes.include?("onebox")
|
||||
next
|
||||
end
|
||||
|
||||
|
@ -426,7 +427,7 @@ class CookedPostProcessor
|
|||
|
||||
next if img["class"]&.include?('onebox-avatar')
|
||||
|
||||
parent_class = img.parent && img.parent["class"]
|
||||
parent_class = parent && parent["class"]
|
||||
width = img["width"].to_i
|
||||
height = img["height"].to_i
|
||||
|
||||
|
|
|
@ -531,6 +531,24 @@ describe CookedPostProcessor do
|
|||
|
||||
expect(cpp.doc.to_s).to eq("<p><img class=\"onebox\" src=\"#{upload.url}\" width=\"\" height=\"\"></p>")
|
||||
end
|
||||
|
||||
it "replaces large image placeholder" do
|
||||
url = 'https://image.com/my-avatar'
|
||||
image_url = 'https://image.com/avatar.png'
|
||||
|
||||
Oneboxer.stubs(:onebox).with(url, anything).returns("<img class='onebox' src='#{image_url}' />")
|
||||
|
||||
post = Fabricate(:post, raw: url)
|
||||
|
||||
post.custom_fields[Post::LARGE_IMAGES] = "[\"//image.com/avatar.png\"]"
|
||||
post.save_custom_fields
|
||||
|
||||
cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)
|
||||
cpp.post_process_oneboxes
|
||||
cpp.post_process_images
|
||||
|
||||
expect(cpp.doc.to_s).to match(/<div class="large-image-placeholder">/)
|
||||
end
|
||||
end
|
||||
|
||||
context ".post_process_oneboxes removes nofollow if add_rel_nofollow_to_user_content is disabled" do
|
||||
|
|
Loading…
Reference in New Issue