A platform for community discussion. Free, open, simple.
FIX: Do not extract links for hotlinked images (#27538)
Bianca Nenciu2ce83b4d2e4d
diff --git a/lib/pretty_text.rb b/lib/pretty_text.rbindex f21706e1a87..d57b0ce0f4a 100644--- a/lib/pretty_text.rb+++ b/lib/pretty_text.rb@@ -403,7 +403,7 @@ module PrettyTextdoc.css("aside.quote a, aside.onebox a, .elided a").remove# remove hotlinked images- doc.css("a.onebox > img").each { |img| img.parent.remove }+ doc.css("a.lightbox > img, a.onebox > img").each { |img| img.parent.remove }# extract all linksdocdiff --git a/spec/lib/pretty_text_spec.rb b/spec/lib/pretty_text_spec.rbindex 79f3297b5ab..2328ae47d4e 100644--- a/spec/lib/pretty_text_spec.rb+++ b/spec/lib/pretty_text_spec.rb@@ -1062,11 +1062,27 @@ RSpec.describe PrettyText doit "does not extract links from hotlinked images" dohtml = <<~HTML<p>- <a href="https://example.com">example</a>+ <a href="https://example.com">example</a>+ </p>- <a href="https://images.pexels.com/photos/1525041/pexels-photo-1525041.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" target="_blank" rel="noopener" class="onebox">- <img src="https://images.pexels.com/photos/1525041/pexels-photo-1525041.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" width="690" height="459">- </a>+ <p>+ <a href="https://images.pexels.com/photos/1525041/pexels-photo-1525041.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" target="_blank" rel="noopener" class="onebox">+ <img src="https://images.pexels.com/photos/1525041/pexels-photo-1525041.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" width="690" height="459">+ </a>+ </p>++ <p>+ <div class="lightbox-wrapper">+ <a class="lightbox" href="//localhost:3000/uploads/default/original/1X/fb7ecffe57b3bc54321635c4f810c5a9396c802c.png" data-download-href="//localhost:3000/uploads/default/fb7ecffe57b3bc54321635c4f810c5a9396c802c" title="image">+ <img src="//localhost:3000/uploads/default/optimized/1X/fb7ecffe57b3bc54321635c4f810c5a9396c802c_2_545x500.png" alt="image" data-base62-sha1="zSPxs3tDdPBuq4dK3uJ1K3Sv8kI" width="545" height="500" data-dominant-color="F9F9F9" />+ <div class="meta">+ <svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg>+ <span class="filename">image</span>+ <span class="informations">808×740 24.8 KB</span>+ <svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg>+ </div>+ </a>+ </div></p>HTML