Rescue regexp timeout
This commit is contained in:
@@ -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>))
|
||||
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
|
||||
%w[ figcaption pre code ].each do |element|
|
||||
assert_equal_html \
|
||||
|
||||
Reference in New Issue
Block a user