diff --git a/app/serializers/api/product_serializer.rb b/app/serializers/api/product_serializer.rb index cf37d7464a..11f228c1e6 100644 --- a/app/serializers/api/product_serializer.rb +++ b/app/serializers/api/product_serializer.rb @@ -21,7 +21,7 @@ class Api::ProductSerializer < ActiveModel::Serializer # return a sanitized html description def description_html - sanitizer.sanitize_content(object.description)&.html_safe + trix_sanitizer.sanitize_content(object.description) end def properties_with_values @@ -37,4 +37,8 @@ class Api::ProductSerializer < ActiveModel::Serializer def sanitizer @sanitizer ||= ContentSanitizer.new end + + def trix_sanitizer + @trix_sanitizer ||= TrixSanitizer.new + end end diff --git a/app/services/trix_sanitizer.rb b/app/services/trix_sanitizer.rb new file mode 100644 index 0000000000..5b4d83b4e6 --- /dev/null +++ b/app/services/trix_sanitizer.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class TrixSanitizer + include ActionView::Helpers::SanitizeHelper + + def sanitize_content(content) + return if content.blank? + + sanitize(content.to_s, scrubber: TrixScrubber.new) + end +end