Skip to content
Snippets Groups Projects
Unverified Commit 27029edf authored by Feanil Patel's avatar Feanil Patel
Browse files

fix: Deal with backward incompatible changes in bleach.

The `bleach` library now expects sets as input for a few parameters and
their defaults have been updated to reflect that.  So we needed to do
some set unions instead of adding lists together in a few places.

Details of the changes can be found here: https://bleach.readthedocs.io/en/latest/changes.html#version-6-0-0-january-23rd-2023
parent 071fccd9
Branches
No related tags found
No related merge requests found
...@@ -1585,7 +1585,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock): ...@@ -1585,7 +1585,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
# For more context on ALLOWED_TAGS and ALLOWED_ATTRIBUTES # For more context on ALLOWED_TAGS and ALLOWED_ATTRIBUTES
# Look into this documentation URL see https://bleach.readthedocs.io/en/latest/clean.html#allowed-tags-tags # Look into this documentation URL see https://bleach.readthedocs.io/en/latest/clean.html#allowed-tags-tags
# This lets all plaintext through. # This lets all plaintext through.
allowed_tags = bleach.sanitizer.ALLOWED_TAGS + ['img'] allowed_tags = bleach.sanitizer.ALLOWED_TAGS | {'img'}
allowed_attributes = dict(bleach.sanitizer.ALLOWED_ATTRIBUTES, **{'img': ['src', 'alt']}) allowed_attributes = dict(bleach.sanitizer.ALLOWED_ATTRIBUTES, **{'img': ['src', 'alt']})
sanitized_comment = bleach.clean(self.score_comment, tags=allowed_tags, attributes=allowed_attributes) sanitized_comment = bleach.clean(self.score_comment, tags=allowed_tags, attributes=allowed_attributes)
......
...@@ -13,7 +13,7 @@ def lti_sanitize(html): ...@@ -13,7 +13,7 @@ def lti_sanitize(html):
""" """
Sanitize a html fragment with bleach. Sanitize a html fragment with bleach.
""" """
allowed_tags = bleach.sanitizer.ALLOWED_TAGS + ['img'] allowed_tags = bleach.sanitizer.ALLOWED_TAGS | {'img'}
allowed_attributes = dict(bleach.sanitizer.ALLOWED_ATTRIBUTES, **{'img': ['src', 'alt']}) allowed_attributes = dict(bleach.sanitizer.ALLOWED_ATTRIBUTES, **{'img': ['src', 'alt']})
sanitized_html = bleach.clean(html, tags=allowed_tags, attributes=allowed_attributes) sanitized_html = bleach.clean(html, tags=allowed_tags, attributes=allowed_attributes)
return mark_safe(sanitized_html) return mark_safe(sanitized_html)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment