FIX: IMDb links were being oneboxed as posters (#13310)

IMDb movie links were being rendered as posters. This was because
IMDb was sending `og:type` as `image` randomly in some cases. To
fix this we'll now default all IMDb links as article type. This will
ensure that the IMDb onebox link includes all the information instead
of showing just a poster without any context.
This commit is contained in:
Arpit Jalan 2021-06-07 18:45:59 +05:30 committed by GitHub
parent 2110fd2638
commit 2e4f07678e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2213 additions and 2 deletions

View File

@ -42,6 +42,10 @@ module Onebox
%w(slideshare.net dailymotion.com livestream.com imgur.com flickr.com)
end
def self.article_html_hosts
%w(imdb.com)
end
def self.host_matches(uri, list)
!!list.find { |h| %r((^|\.)#{Regexp.escape(h)}$).match(uri.host) }
end
@ -59,7 +63,7 @@ module Onebox
end
def placeholder_html
return article_html if is_article?
return article_html if (is_article? || force_article_html?)
return image_html if is_image?
return Onebox::Helpers.video_placeholder_html if is_video? || is_card?
return Onebox::Helpers.generic_placeholder_html if is_embedded?
@ -150,7 +154,7 @@ module Onebox
end
def generic_html
return article_html if is_article?
return article_html if (is_article? || force_article_html?)
return video_html if is_video?
return image_html if is_image?
return embedded_html if is_embedded?
@ -207,6 +211,10 @@ module Onebox
options[:allowed_iframe_regexes]&.any? { |r| src =~ r }
end
def force_article_html?
AllowlistedGenericOnebox.host_matches(uri, AllowlistedGenericOnebox.article_html_hosts) && (has_text? || is_image_article?)
end
def card_html
escaped_url = ::Onebox::Helpers.normalize_url_for_output(data[:player])

2186
spec/fixtures/onebox/imdb.response vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -182,4 +182,21 @@ describe Onebox::Engine::AllowlistedGenericOnebox do
end
end
end
describe 'article html hosts' do
context 'returns article_html for hosts in article_html_hosts' do
before do
stub_request(:get, "https://www.imdb.com/title/tt0108002/")
.to_return(status: 200, body: onebox_response('imdb'))
end
it 'shows article onebox' do
onebox = described_class.new("https://www.imdb.com/title/tt0108002/")
expect(onebox.to_html).to include("https://www.imdb.com/title/tt0108002")
expect(onebox.to_html).to include("https://m.media-amazon.com/images/M/MV5BZGUzMDU1YmQtMzBkOS00MTNmLTg5ZDQtZjY5Njk4Njk2MmRlXkEyXkFqcGdeQXVyNjc1NTYyMjg@._V1_FMjpg_UX1000_.jpg")
expect(onebox.to_html).to include("Rudy (1993) - IMDb")
expect(onebox.to_html).to include("Rudy: Directed by David Anspaugh. With Sean Astin, Jon Favreau, Ned Beatty, Greta Lind. Rudy has always been told that he was too small to play college football.")
end
end
end
end