Skip to content

Commit

Permalink
Merge 88ff9bb into 5d98e92
Browse files Browse the repository at this point in the history
  • Loading branch information
gabn88 committed Jul 18, 2022
2 parents 5d98e92 + 88ff9bb commit 9372d1f
Showing 1 changed file with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import bleach

BLEACH_INSTALLED = True
BLEACH_VERSION = bleach.__version__
except ImportError:
BLEACH_INSTALLED = False
BLEACH_VERSION = False


__title__ = "fobi.contrib.plugins.form_elements.content.content_richtext.forms"
__author__ = "Frantisek Holop <fholop@ripe.net>"
Expand Down Expand Up @@ -47,17 +50,37 @@ def clean_text(self):
"FOBI_PLUGIN_CONTENT_RICHTEXT_ALLOWED_ATTRIBUTES",
bleach.ALLOWED_ATTRIBUTES,
)
allowed_styles = getattr(
settings,
"FOBI_PLUGIN_CONTENT_RICHTEXT_ALLOWED_STYLES",
bleach.ALLOWED_STYLES,
)

if BLEACH_VERSION > '5.0.0':
from bleach.css_sanitizer import CSSSanitizer
from bleach.css_sanitizer import ALLOWED_CSS_PROPERTIES
css_sanitizer = CSSSanitizer(allowed_css_properties=getattr(
settings,
"FOBI_PLUGIN_CONTENT_RICHTEXT_ALLOWED_STYLES",
ALLOWED_CSS_PROPERTIES,
))
return bleach.clean(
text=self.cleaned_data["text"],
tags=allowed_tags,
attributes=allowed_attrs,
strip=True,
strip_comments=True,
css_sanitizer=css_sanitizer
)

else:

allowed_styles = getattr(
settings,
"FOBI_PLUGIN_CONTENT_RICHTEXT_ALLOWED_STYLES",
bleach.ALLOWED_STYLES,
)

return bleach.clean(
text=self.cleaned_data["text"],
tags=allowed_tags,
attributes=allowed_attrs,
styles=allowed_styles,
strip=True,
strip_comments=True,
)
return bleach.clean(
text=self.cleaned_data["text"],
tags=allowed_tags,
attributes=allowed_attrs,
styles=allowed_styles,
strip=True,
strip_comments=True,
)

0 comments on commit 9372d1f

Please sign in to comment.