diff --git a/lib/email/styles.rb b/lib/email/styles.rb index 701c9ecb93e..04f2935fa4f 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -150,7 +150,7 @@ module Email next end - src_uri = URI(i['src']) + src_uri = i["data-original-href"].present? ? URI(i["data-original-href"]) : URI(i['src']) # If an iframe is protocol relative, use SSL when displaying it display_src = "#{src_uri.scheme || 'https'}://#{src_uri.host}#{src_uri.path}#{src_uri.query.nil? ? '' : '?' + src_uri.query}#{src_uri.fragment.nil? ? '' : '#' + src_uri.fragment}" i.replace "

#{CGI.escapeHTML(display_src)}

" diff --git a/spec/components/email/styles_spec.rb b/spec/components/email/styles_spec.rb index d99440dc3e6..8e85d7bdc6e 100644 --- a/spec/components/email/styles_spec.rb +++ b/spec/components/email/styles_spec.rb @@ -106,6 +106,15 @@ describe Email::Styles do expect(frag.at('iframe')).to be_blank expect(frag.at('a')).to be_blank end + + it "prefers data-original-href attribute to get iframe link" do + original_url = "https://vimeo.com/329875646" + iframe_url = "https://player.vimeo.com/video/329875646" + frag = html_fragment("") + expect(frag.at('iframe')).to be_blank + expect(frag.at('a')).to be_present + expect(frag.at('a')['href']).to eq(original_url) + end end context "rewriting protocol relative URLs to the forum" do