Fix handling of malformed/unusual HTML (#34201)

This commit is contained in:
Claire 2025-03-18 15:50:41 +01:00 committed by GitHub
parent 4ad5d8e6e5
commit 547658f086
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 38 additions and 8 deletions

View file

@ -2,11 +2,18 @@
module Admin::Trends::StatusesHelper
def one_line_preview(status)
text = if status.local?
status.text.split("\n").first
else
Nokogiri::HTML5(status.text).css('html > body > *').first&.text
end
text = begin
if status.local?
status.text.split("\n").first
else
Nokogiri::HTML5(status.text).css('html > body > *').first&.text
end
rescue ArgumentError
# This can happen if one of the Nokogumbo limits is encountered
# Unfortunately, it does not use a more precise error class
# nor allows more graceful handling
''
end
return '' if text.blank?