diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index 8daef42e89e..8797a44cd10 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -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 diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 27ceeb6b63a..bc25be8e604 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -531,6 +531,24 @@ describe CookedPostProcessor do expect(cpp.doc.to_s).to eq("

") 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("") + + 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(/
/) + end end context ".post_process_oneboxes removes nofollow if add_rel_nofollow_to_user_content is disabled" do