Fix handling of malformed/unusual HTML (#34201)

This commit is contained in:
Claire 2025-03-18 15:50:41 +01:00
parent 8197e65cb3
commit 4cb3fe35be
4 changed files with 38 additions and 8 deletions

View file

@ -24,7 +24,15 @@ class EmojiFormatter
def to_s
return html if custom_emojis.empty? || html.blank?
tree = Nokogiri::HTML5.fragment(html)
begin
tree = Nokogiri::HTML5.fragment(html)
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
return ''
end
tree.xpath('./text()|.//text()[not(ancestor[@class="invisible"])]').to_a.each do |node|
i = -1
inside_shortname = false