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

getVocabulary: Do run scrub_html on individual items #187

Merged
merged 1 commit into from
Jul 30, 2024
Merged
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
18 changes: 12 additions & 6 deletions src/recensio/plone/browser/vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@
from Products.CMFCore.utils import getToolByName
from Products.MimetypesRegistry.MimeTypeItem import guess_icon_path
from Products.MimetypesRegistry.MimeTypeItem import PREFIX
from Products.PortalTransforms.transforms.safe_html import hasScript
from Products.PortalTransforms.transforms.safe_html import SafeHTML
from zope.i18n import translate

import itertools


class RecensioVocabularyView(VocabularyView):
def maybe_scrub(self, value):
if value and (hasScript(value) or "<" in value):
transform = SafeHTML()
return transform.scrub_html(value)
return value

def __call__(self): # noqa: C901
"""
Accepts GET parameters of:
Expand Down Expand Up @@ -103,7 +110,6 @@ def __call__(self): # noqa: C901
attributes = attributes.split(",")

translate_ignored = self.get_translated_ignored()
transform = SafeHTML()
if attributes:
base_path = self.get_base_path(context)
sm = getSecurityManager()
Expand Down Expand Up @@ -154,15 +160,15 @@ def __call__(self): # noqa: C901
else:
items = [
{
"id": item.value,
"text": (item.title if item.title else ""),
"id": unescape(self.maybe_scrub(item.value)),
"text": (
unescape(self.maybe_scrub(item.title)) if item.title else ""
),
}
for item in results
]

if total == 0:
total = len(items)

return unescape(
transform.scrub_html(json_dumps({"results": items, "total": total}))
)
return json_dumps({"results": items, "total": total})
Loading