mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-12 23:27:48 +00:00
16 lines
467 B
Ruby
16 lines
467 B
Ruby
# frozen_string_literal: true
|
|
|
|
# Keeps only allowed HTML.
|
|
#
|
|
# We store some rich text as HTML in attributes of models like Enterprise.
|
|
# We offer an editor which supports certain tags but you can't insert just any
|
|
# HTML, which would be dangerous.
|
|
class HtmlSanitizer
|
|
def self.sanitize(html)
|
|
@sanitizer ||= Rails::HTML5::SafeListSanitizer.new
|
|
@sanitizer.sanitize(
|
|
html, tags: %w[h1 h2 h3 h4 p br b i u a], attributes: %w[href target],
|
|
)
|
|
end
|
|
end
|