mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Sanitize content when display it on shop
Use the TrixSanitizer | TrixScrubber
This commit is contained in:
@@ -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
|
||||
|
||||
11
app/services/trix_sanitizer.rb
Normal file
11
app/services/trix_sanitizer.rb
Normal 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
|
||||
Reference in New Issue
Block a user