A platform for community discussion. Free, open, simple.
FIX: skip image dimensions in oembed for rich data types (#37108)
David Battersbyfb2a2c02f106
diff --git a/lib/onebox/engine/allowlisted_generic_onebox.rb b/lib/onebox/engine/allowlisted_generic_onebox.rbindex cbb8a0fb6df..b2cdc04783c 100644--- a/lib/onebox/engine/allowlisted_generic_onebox.rb+++ b/lib/onebox/engine/allowlisted_generic_onebox.rb@@ -228,7 +228,7 @@ module Oneboxenddef is_embedded?- return false unless data[:html] && data[:height]+ return false if data[:html].blank?return true if AllowlistedGenericOnebox.html_providers.include?(data[:provider_name])return false unless data[:html]["iframe"]@@ -300,7 +300,7 @@ module Oneboxif iframe = fragment.at_css("iframe")iframe.remove_attribute("style")iframe["width"] = data[:width] || "100%"- iframe["height"] = data[:height]+ iframe["height"] = data[:height] if data[:height].present?iframe["scrolling"] = "no"iframe["frameborder"] = "0"enddiff --git a/lib/onebox/engine/standard_embed.rb b/lib/onebox/engine/standard_embed.rbindex b3f1e6227d7..378e2803c5d 100644--- a/lib/onebox/engine/standard_embed.rb+++ b/lib/onebox/engine/standard_embed.rb@@ -163,8 +163,9 @@ module Onebox@json_ld ||= Onebox::JsonLd.new(html_doc)end- def set_from_normalizer_data(normalizer)+ def set_from_normalizer_data(normalizer, skip_dimensions: false)normalizer.data.each do |k, _|+ next if skip_dimensions && k.in?(%i[width height])v = normalizer.public_send(k)@raw[k] ||= v unless v.nil?end@@ -183,7 +184,8 @@ module Oneboxdef set_oembed_data_on_rawoembed = get_oembed- set_from_normalizer_data(oembed)+ skip_dimensions = oembed.data[:type] == "rich"+ set_from_normalizer_data(oembed, skip_dimensions:)enddef set_json_ld_data_on_rawdiff --git a/spec/lib/cooked_post_processor_spec.rb b/spec/lib/cooked_post_processor_spec.rbindex 6777b7a45c5..1c1ad3f5776 100644--- a/spec/lib/cooked_post_processor_spec.rb+++ b/spec/lib/cooked_post_processor_spec.rb@@ -1497,9 +1497,9 @@ RSpec.describe CookedPostProcessor doenddescribe "#post_process_oneboxes with square image" do- it "generates a onebox-avatar class" do- url = "https://square-image.com/onebox"+ fab!(:post) { Fabricate(:post, raw: "https://square-image.com/onebox") }+ it "generates a onebox-avatar class" dobody = <<~HTML<html><head>@@ -1510,16 +1510,14 @@ RSpec.describe CookedPostProcessor do</html>HTML- stub_request(:head, url)- stub_request(:get, url).to_return(body: body)+ stub_request(:head, post.raw)+ stub_request(:get, post.raw).to_return(body: body)# not an ideal stub but shipping the whole image to fast image can add# a lot of cost to this teststub_image_size(width: 200, height: 200)- post = Fabricate.build(:post, raw: url)cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)-cpp.post_process_oneboxesexpect(cpp.doc.to_s).not_to include("aspect-image")diff --git a/spec/lib/onebox/engine/standard_embed_spec.rb b/spec/lib/onebox/engine/standard_embed_spec.rbindex 09dadda3f32..51ac202f29c 100644--- a/spec/lib/onebox/engine/standard_embed_spec.rb+++ b/spec/lib/onebox/engine/standard_embed_spec.rb@@ -101,6 +101,16 @@ RSpec.describe Onebox::Engine::StandardEmbed doexpect(instance.raw).to eq({ description: "description" })end+ it "skips oembed dimensions for rich embeds" do+ Onebox::Helpers.stubs(fetch_html_doc: nil)+ Onebox::Oembed+ .any_instance+ .stubs(:data)+ .returns({ type: "rich", width: 600, height: 338, title: "Title" })++ expect(instance.raw).to eq({ type: "rich", title: "Title" })+ end+it "does not override data with json_ld data" doOnebox::Helpers.stubs(fetch_html_doc: nil)Onebox::JsonLd.any_instance.stubs(:data).returns({ title: "i do not want to override" })