summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEffy Elden <effy@effy.space>2022-12-20 15:19:35 +1100
committerGitHub <noreply@github.com>2022-12-20 15:19:35 +1100
commit81e23191cff08cdd94e088ddcc3e48d0d84f5c09 (patch)
tree8056aa3c2af06f3e9702085e12f694c330463450
parentc1de6730604f526a6c2d19adcf6f195352de0641 (diff)
Use rich OEmbed content when it conforms to Mastodon's sanitizationsupport-rich-oembed
-rw-r--r--app/services/fetch_link_card_service.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb
index e5b5b730eca..46ca7d940c0 100644
--- a/app/services/fetch_link_card_service.rb
+++ b/app/services/fetch_link_card_service.rb
@@ -136,8 +136,13 @@ class FetchLinkCardService < BaseService
@card.html = Sanitize.fragment(embed[:html], Sanitize::Config::MASTODON_OEMBED)
@card.image_remote_url = (url + embed[:thumbnail_url]).to_s if embed[:thumbnail_url].present?
when 'rich'
- # Most providers rely on <script> tags, which is a no-no
- return false
+ sanitized_rich_html = Sanitize.fragment(embed[:html], Sanitize::Config::MASTODON_OEMBED)
+ return false if sanitized_rich_html != embed[:html]
+
+ @card.width = embed[:width].presence || 0
+ @card.height = embed[:height].presence || 0
+ @card.html = sanitized_rich_html
+ @card.image_remote_url = (url + embed[:thumbnail_url]).to_s if embed[:thumbnail_url].present?
end
@card.save_with_optional_image!