Fix #4262: Exception when using Twitter video image links.

This commit is contained in:
evazion
2020-01-15 15:20:33 -06:00
parent 617e1ca98a
commit e42881fbbf
2 changed files with 9 additions and 2 deletions

View File

@@ -80,8 +80,10 @@ module Sources::Strategies
end
def preview_urls
image_urls.map do |x|
x.sub(%r!\.(jpg|jpeg|png|gif)(?::orig)?\z!i, '.\1:small')
return image_urls if api_response.blank?
api_response.dig(:extended_entities, :media).to_a.map do |media|
media[:media_url_https] + ":small"
end
end

View File

@@ -32,6 +32,7 @@ module Sources
should "get the correct urls" do
assert_equal("https://video.twimg.com/ext_tw_video/859073467769126913/pu/vid/1280x720/cPGgVROXHy3yrK6u.mp4", @site.image_url)
assert_equal(["https://pbs.twimg.com/ext_tw_video_thumb/859073467769126913/pu/img/VKHGdXPsqKASBTvm.jpg:small"], @site.preview_urls)
assert_equal("https://twitter.com/CincinnatiZoo/status/859073537713328129", @site.canonical_url)
end
end
@@ -44,6 +45,10 @@ module Sources
should "get the image url" do
assert_equal("https://video.twimg.com/tweet_video/C-1Tns7WsAAqvqn.mp4", @site.image_url)
end
should "get the preview urls" do
assert_equal(["https://pbs.twimg.com/tweet_video_thumb/C-1Tns7WsAAqvqn.jpg:small"], @site.preview_urls)
end
end
context "A twitter summary card from twitter with a :large image" do