handle nil product descriptions

This commit is contained in:
Andy Brett
2021-01-13 20:57:27 -08:00
parent 67e5825739
commit bbd7fd0350
2 changed files with 7 additions and 3 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
sanitizer.sanitize_content(object.description)&.html_safe
end
def properties_with_values

View File

@@ -14,15 +14,19 @@ class ContentSanitizer
}.freeze
def strip_content(content)
return unless content.present?
content = strip_tags(content.to_s.strip)
filter_characters(content) if content.present?
filter_characters(content)
end
def sanitize_content(content)
return unless content.present?
content = sanitize(content.to_s, tags: ALLOWED_TAGS, attributes: ALLOWED_ATTRIBUTES)
filter_characters(content) if content.present?
filter_characters(content)
end
private