diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index e78fa9c6366..b0f306d9b46 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -539,6 +539,7 @@ class CookedPostProcessor next if img["class"]&.include?('onebox-avatar') + parent = parent&.parent if parent&.name == "a" parent_class = parent && parent["class"] width = img["width"].to_i height = img["height"].to_i @@ -572,8 +573,8 @@ class CookedPostProcessor elsif (parent_class&.include?("instagram-images") || parent_class&.include?("tweet-images") || parent_class&.include?("scale-images")) && width > 0 && height > 0 img.remove_attribute("width") img.remove_attribute("height") - img.parent["class"] = "aspect-image-full-size" - img.parent["style"] = "--aspect-ratio:#{width}/#{height};" + parent["class"] = "aspect-image-full-size" + parent["style"] = "--aspect-ratio:#{width}/#{height};" end end diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index 9ec8b3472a4..156e1f81cb4 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -893,6 +893,31 @@ describe CookedPostProcessor do end end + context "#post_process_oneboxes with oneboxed image" do + let(:post) { build(:post_with_youtube, id: 123) } + let(:cpp) { CookedPostProcessor.new(post, invalidate_oneboxes: true) } + + it "applies aspect ratio to container" do + Oneboxer.expects(:onebox) + .with("http://www.youtube.com/watch?v=9bZkp7q19f0", invalidate_oneboxes: true, user_id: nil, category_id: post.topic.category_id) + .returns("