Rescue regexp timeout
This commit is contained in:
@@ -71,6 +71,9 @@ class AutoLinkScrubber < Loofah::Scrubber
|
|||||||
end
|
end
|
||||||
|
|
||||||
links
|
links
|
||||||
|
rescue Regexp::TimeoutError => error
|
||||||
|
Sentry.capture_exception error if Fizzy.saas?
|
||||||
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
def clean_url(url)
|
def clean_url(url)
|
||||||
|
|||||||
@@ -104,6 +104,27 @@ class HtmlHelperTest < ActionView::TestCase
|
|||||||
format_html(%(<p>Contact us at <a href="mailto:support@example.com">support@example.com</a></p>))
|
format_html(%(<p>Contact us at <a href="mailto:support@example.com">support@example.com</a></p>))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "gracefully handle regexp timeout by skipping auto-linking" do
|
||||||
|
input = "<p>Check this: https://example.com</p>"
|
||||||
|
|
||||||
|
String.class_eval do
|
||||||
|
alias_method :original_scan, :scan
|
||||||
|
define_method(:scan) do |*args, &block|
|
||||||
|
if args.first == AutoLinkScrubber::AUTOLINK_REGEXP
|
||||||
|
raise Regexp::TimeoutError
|
||||||
|
end
|
||||||
|
original_scan(*args, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal_html %(<p>Check this: https://example.com</p>), format_html(input)
|
||||||
|
ensure
|
||||||
|
String.class_eval do
|
||||||
|
alias_method :scan, :original_scan
|
||||||
|
remove_method :original_scan
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "don't autolink content in excluded elements" do
|
test "don't autolink content in excluded elements" do
|
||||||
%w[ figcaption pre code ].each do |element|
|
%w[ figcaption pre code ].each do |element|
|
||||||
assert_equal_html \
|
assert_equal_html \
|
||||||
|
|||||||
Reference in New Issue
Block a user