base.rb 703 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class HtmlSanitizer
  3. class Base
  4. def with_timeout(string, &)
  5. Timeout.timeout(PROCESSING_TIMEOUT, &)
  6. rescue Timeout::Error
  7. Rails.logger.error "Could not process string via #{self.class.name} in #{PROCESSING_TIMEOUT} seconds. Current state: #{string}"
  8. UNPROCESSABLE_HTML_MSG
  9. end
  10. def loop_string(string, scrubber)
  11. string = Loofah.fragment(string).scrub!(scrubber).to_html
  12. old_string = string
  13. loop do
  14. string = Loofah.fragment(string).scrub!(scrubber).to_html
  15. break if string == old_string
  16. old_string = string
  17. end
  18. string
  19. end
  20. end
  21. end