-
Notifications
You must be signed in to change notification settings - Fork 35
sanitizer: allow style for description #2150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sanitizer: allow style for description #2150
Conversation
76e58c4 to
f4b16c2
Compare
| class SanitizedHTMLWithCSS(fields.String): | ||
| """Enhanced SanitizedHTML supporting inline CSS sanitization. | ||
| Fully compatible with marshmallow_utils.fields.SanitizedHTML, | ||
| but adds CSS. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| tags=None, | ||
| attrs=None, | ||
| css_styles=None, | ||
| *args, | ||
| **kwargs, | ||
| ): | ||
| """ | ||
| :param tags: Allowed HTML tags. | ||
| :param attrs: Allowed HTML attributes per tag. | ||
| :param css_styles: List of allowed CSS properties (e.g., ["color"]). | ||
| """ | ||
| super().__init__(*args, **kwargs) | ||
|
|
||
| self.tags = tags | ||
| self.attrs = attrs | ||
| self.css_styles = css_styles | ||
|
|
||
| def _deserialize(self, value, attr, data, **kwargs): | ||
| """Run bleach sanitize with CSS support.""" | ||
| value = super()._deserialize(value, attr, data, **kwargs) | ||
|
|
||
| return sanitize_html( | ||
| value, | ||
| tags=self.tags, | ||
| attrs=self.attrs, | ||
| css_styles=self.css_styles, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
marshmallow_utils SanitizedHTML doesn't support css_styles
f4b16c2 to
2430e17
Compare
| "strong": ["style"], | ||
| "em": ["style"], | ||
| "u": ["style"], | ||
| "sup": ["style"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are these attrs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked, and span and p should be enough I'll remove these
ntarocco
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
2430e17 to
49f6b28
Compare
Uh oh!
There was an error while loading. Please reload this page.