Skip to content

Commit 1ebaff2

Browse files
authoredJul 30, 2024
Merge pull request #187 from syslabcom/scrum-2408-getVocabulary-2
getVocabulary: Do run scrub_html on individual items
2 parents a467cb5 + 256fc2c commit 1ebaff2

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed
 

‎src/recensio/plone/browser/vocabulary.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414
from Products.CMFCore.utils import getToolByName
1515
from Products.MimetypesRegistry.MimeTypeItem import guess_icon_path
1616
from Products.MimetypesRegistry.MimeTypeItem import PREFIX
17+
from Products.PortalTransforms.transforms.safe_html import hasScript
1718
from Products.PortalTransforms.transforms.safe_html import SafeHTML
1819
from zope.i18n import translate
1920

2021
import itertools
2122

2223

2324
class RecensioVocabularyView(VocabularyView):
25+
def maybe_scrub(self, value):
26+
if value and (hasScript(value) or "<" in value):
27+
transform = SafeHTML()
28+
return transform.scrub_html(value)
29+
return value
30+
2431
def __call__(self): # noqa: C901
2532
"""
2633
Accepts GET parameters of:
@@ -103,7 +110,6 @@ def __call__(self): # noqa: C901
103110
attributes = attributes.split(",")
104111

105112
translate_ignored = self.get_translated_ignored()
106-
transform = SafeHTML()
107113
if attributes:
108114
base_path = self.get_base_path(context)
109115
sm = getSecurityManager()
@@ -154,15 +160,15 @@ def __call__(self): # noqa: C901
154160
else:
155161
items = [
156162
{
157-
"id": item.value,
158-
"text": (item.title if item.title else ""),
163+
"id": unescape(self.maybe_scrub(item.value)),
164+
"text": (
165+
unescape(self.maybe_scrub(item.title)) if item.title else ""
166+
),
159167
}
160168
for item in results
161169
]
162170

163171
if total == 0:
164172
total = len(items)
165173

166-
return unescape(
167-
transform.scrub_html(json_dumps({"results": items, "total": total}))
168-
)
174+
return json_dumps({"results": items, "total": total})

0 commit comments

Comments
 (0)