FIX: vimeo iframe url when data-original-href is missing (#18894)

This commit is contained in:
Ghassan Maslamani 2023-01-31 12:00:27 +01:00 committed by GitHub
parent bdf8815b71
commit 96a6bb69b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -527,7 +527,7 @@ module PrettyText
if iframe["data-original-href"].present? if iframe["data-original-href"].present?
vimeo_url = UrlHelper.normalized_encode(iframe["data-original-href"]) vimeo_url = UrlHelper.normalized_encode(iframe["data-original-href"])
else else
vimeo_id = iframe["src"].split("/").last vimeo_id = iframe["src"].split("/").last.sub("?h=", "/")
vimeo_url = "https://vimeo.com/#{vimeo_id}" vimeo_url = "https://vimeo.com/#{vimeo_id}"
end end
iframe.replace Nokogiri::HTML5.fragment("<p><a href='#{vimeo_url}'>#{vimeo_url}</a></p>") iframe.replace Nokogiri::HTML5.fragment("<p><a href='#{vimeo_url}'>#{vimeo_url}</a></p>")

View File

@ -1298,6 +1298,14 @@ RSpec.describe PrettyText do
) )
end end
it "creates a valid URL when data-original-href is missing from Vimeo link" do
html =
'<iframe src="https://player.vimeo.com/video/508864124?h=fcbbcc92fa" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>'
expect(PrettyText.format_for_email(html, post)).to match(
"https://vimeo.com/508864124/fcbbcc92fa",
)
end
describe "#convert_vimeo_iframes" do describe "#convert_vimeo_iframes" do
it "converts <iframe> to <a>" do it "converts <iframe> to <a>" do
html = <<~HTML html = <<~HTML