mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: secure_media stripping on lightboxes, non-image links (#11121)
- Fixes stripping of lightboxes with empty srcset attribute - Does not fail when email has links with secure media URLs but no child image elements
This commit is contained in:
@@ -414,12 +414,18 @@ module PrettyText
|
||||
target = non_image_media ? a.parent : a
|
||||
next if target.to_s.include?('stripped-secure-view-media')
|
||||
|
||||
next if a.css('img[src]').empty? && !non_image_media
|
||||
|
||||
if a.classes.include?('lightbox')
|
||||
# we are using the first image from the srcset here so we get the
|
||||
# optimized image instead of the possibly huge original
|
||||
img = a.css('img[src]').first
|
||||
srcset = img.attributes['srcset'].value
|
||||
url = srcset.split(',').first
|
||||
srcset = img&.attributes['srcset']&.value
|
||||
if srcset
|
||||
# if available, use the first image from the srcset here
|
||||
# so we get the optimized image instead of the possibly huge original
|
||||
url = srcset.split(',').first
|
||||
else
|
||||
url = img['src']
|
||||
end
|
||||
a.add_next_sibling secure_media_placeholder(doc, url, width: img['width'], height: img['height'])
|
||||
a.remove
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user