Merge pull request #2737 from basecamp/remember-regexp-timeout

Stop scrubbing after first regexp timeout
This commit is contained in:
Zacharias Knudsen
2026-03-20 12:16:34 +01:00
committed by GitHub
2 changed files with 5 additions and 2 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
module HtmlHelper
def format_html(html)
Loofah::HTML5::DocumentFragment.parse(html).scrub!(AutoLinkScrubber.new).to_html.html_safe
@auto_link_scrubber ||= AutoLinkScrubber.new
Loofah::HTML5::DocumentFragment.parse(html).scrub!(@auto_link_scrubber).to_html.html_safe
end
def card_html_title(card)
+3 -1
View File
@@ -20,12 +20,13 @@ class AutoLinkScrubber < Loofah::Scrubber
def initialize
@direction = :top_down
@regexp_timeout_reported = false
end
def scrub(node)
return Loofah::Scrubber::STOP if EXCLUDED_ELEMENTS.include?(node.name)
if node.text?
if node.text? && !@regexp_timeout_reported
replacement = autolink_text_node(node)
node.replace(replacement) if replacement
end
@@ -73,6 +74,7 @@ class AutoLinkScrubber < Loofah::Scrubber
links
rescue Regexp::TimeoutError => error
Sentry.capture_exception error if Fizzy.saas?
@regexp_timeout_reported = true
[]
end