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 module HtmlHelper
def format_html(html) 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 end
def card_html_title(card) def card_html_title(card)
+3 -1
View File
@@ -20,12 +20,13 @@ class AutoLinkScrubber < Loofah::Scrubber
def initialize def initialize
@direction = :top_down @direction = :top_down
@regexp_timeout_reported = false
end end
def scrub(node) def scrub(node)
return Loofah::Scrubber::STOP if EXCLUDED_ELEMENTS.include?(node.name) return Loofah::Scrubber::STOP if EXCLUDED_ELEMENTS.include?(node.name)
if node.text? if node.text? && !@regexp_timeout_reported
replacement = autolink_text_node(node) replacement = autolink_text_node(node)
node.replace(replacement) if replacement node.replace(replacement) if replacement
end end
@@ -73,6 +74,7 @@ class AutoLinkScrubber < Loofah::Scrubber
links links
rescue Regexp::TimeoutError => error rescue Regexp::TimeoutError => error
Sentry.capture_exception error if Fizzy.saas? Sentry.capture_exception error if Fizzy.saas?
@regexp_timeout_reported = true
[] []
end end