Sanitize content when display it on shop

Use the TrixSanitizer | TrixScrubber
This commit is contained in:
Jean-Baptiste Bellet
2023-06-29 09:20:48 +02:00
parent f9bc00e5cd
commit 4c27e79519
2 changed files with 16 additions and 1 deletions

View File

@@ -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

View File

@@ -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