Merge pull request #6458 from vinothkannans/fix-giphy

FIX: Display large/broken image placeholders for image oneboxes
This commit is contained in:
Vinoth Kannan 2018-10-07 18:08:54 +05:30 committed by GitHub
commit 4000dddd32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 4 deletions

View File

@ -167,8 +167,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
@ -440,9 +438,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
@ -456,7 +457,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

View File

@ -541,6 +541,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