Stop scrubbing after first regexp timeout
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user