Skip to content
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

Shortcut in safe_html #66

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Products/PortalTransforms/transforms/safe_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from lxml_html_clean import Cleaner
from plone.base.interfaces import IFilterSchema
from plone.base.utils import safe_bytes
from plone.base.utils import safe_text
from plone.registry.interfaces import IRegistry
from Products.PortalTransforms.interfaces import ITransform
from Products.PortalTransforms.libtransforms.utils import bodyfinder
Expand Down Expand Up @@ -183,6 +184,14 @@ def cleaner_options(self):
return options

def scrub_html(self, orig):
orig_text = safe_text(orig)
# short cut if no html or script is detected
if not orig or not (
hasScript(orig_text)
or "<" in orig_text
or any(entity in orig_text for entity in html5entities.values())
):
return orig_text
# append html tag to create a dummy parent for the tree
html_parser = html.HTMLParser(encoding="utf-8")
orig = safe_bytes(orig)
Expand Down
1 change: 1 addition & 0 deletions news/66.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Shortcut in safe_html: Check for signs of html or script, skip further processing if none are found.