From 95a45aa651c801fe1c0829d8e3a4eb19962ed1dd Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 20 Mar 2026 16:02:02 -0400 Subject: [PATCH] Don't memoize AutoLinkScrubber across format_html calls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scrubber was memoized on the view helper in b0fa6525 so that @regexp_timeout_reported would stop scanning remaining text nodes after a timeout. But memoizing on the helper leaks that flag across all format_html calls for the entire request — if one comment triggers a timeout, every subsequent comment on the page loses auto-linking. Use a fresh scrubber per call. The @regexp_timeout_reported flag still works within a single document's scrub, which is the intended scope. Co-Authored-By: Claude Opus 4.6 (1M context) --- app/helpers/html_helper.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/helpers/html_helper.rb b/app/helpers/html_helper.rb index f399274f4..7b65d34cf 100644 --- a/app/helpers/html_helper.rb +++ b/app/helpers/html_helper.rb @@ -1,7 +1,6 @@ module HtmlHelper def format_html(html) - @auto_link_scrubber ||= AutoLinkScrubber.new - Loofah::HTML5::DocumentFragment.parse(html).scrub!(@auto_link_scrubber).to_html.html_safe + Loofah::HTML5::DocumentFragment.parse(html).scrub!(AutoLinkScrubber.new).to_html.html_safe end def card_html_title(card)