From bd9e47e9bed132b9164ce7cb357e84f5f2b3c72a Mon Sep 17 00:00:00 2001 From: ThibG Date: Mon, 10 Sep 2018 18:26:28 +0200 Subject: [PATCH] Handle relative URLs when fetching OEmbed/OpenGraph cards (#8669) --- app/services/fetch_link_card_service.rb | 18 ++++++++++-------- app/services/fetch_oembed_service.rb | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb index 560a81768..ea94e2491 100644 --- a/app/services/fetch_link_card_service.rb +++ b/app/services/fetch_link_card_service.rb @@ -87,34 +87,36 @@ class FetchLinkCardService < BaseService end def attempt_oembed - embed = FetchOEmbedService.new.call(@url, html: @html) + service = FetchOEmbedService.new + embed = service.call(@url, html: @html) + url = Addressable::URI.parse(service.endpoint_url) return false if embed.nil? @card.type = embed[:type] @card.title = embed[:title] || '' @card.author_name = embed[:author_name] || '' - @card.author_url = embed[:author_url] || '' + @card.author_url = embed[:author_url].present? ? (url + embed[:author_url]).to_s : '' @card.provider_name = embed[:provider_name] || '' - @card.provider_url = embed[:provider_url] || '' + @card.provider_url = embed[:provider_url].present? ? (url + embed[:provider_url]).to_s : '' @card.width = 0 @card.height = 0 case @card.type when 'link' - @card.image_remote_url = embed[:thumbnail_url] if embed[:thumbnail_url].present? + @card.image_remote_url = (url + embed[:thumbnail_url]).to_s if embed[:thumbnail_url].present? when 'photo' return false if embed[:url].blank? - @card.embed_url = embed[:url] - @card.image_remote_url = embed[:url] + @card.embed_url = (url + embed[:url]).to_s + @card.image_remote_url = (url + embed[:url]).to_s @card.width = embed[:width].presence || 0 @card.height = embed[:height].presence || 0 when 'video' @card.width = embed[:width].presence || 0 @card.height = embed[:height].presence || 0 @card.html = Formatter.instance.sanitize(embed[:html], Sanitize::Config::MASTODON_OEMBED) - @card.image_remote_url = embed[:thumbnail_url] if embed[:thumbnail_url].present? + @card.image_remote_url = (url + embed[:thumbnail_url]).to_s if embed[:thumbnail_url].present? when 'rich' # Most providers rely on