Skip to content

Commit efee17c

Browse files
fix(serializer): do not remove HTML tags for titles
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4bb709e commit efee17c

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

cds/modules/records/serializers/json.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
has_read_record_eos_path_permission,
3232
has_read_record_permission,
3333
)
34-
from ..utils import HTMLTagRemover, parse_video_chapters, remove_html_tags
34+
from ..utils import HTMLTagRemover, parse_video_chapters
3535
from marshmallow_utils.html import sanitize_html, ALLOWED_HTML_ATTRS, ALLOWED_CSS_STYLES
3636

3737
CUSTOM_ALLOWED_ATTRS = {
@@ -61,9 +61,6 @@ def _sanitize_metadata(self, metadata):
6161
if "title" in metadata and "title" in metadata["title"]:
6262
title = metadata["title"]["title"]
6363
title = self.html_tag_remover.unescape(title)
64-
metadata["title"]["title"] = remove_html_tags(
65-
self.html_tag_remover, title
66-
)
6764

6865
if "description" in metadata:
6966
description = metadata["description"]
@@ -79,9 +76,6 @@ def _sanitize_metadata(self, metadata):
7976
if "title" in t and "title" in t["title"]:
8077
t_title = t["title"]["title"]
8178
t_title = self.html_tag_remover.unescape(t_title)
82-
t["title"]["title"] = remove_html_tags(
83-
self.html_tag_remover, t_title
84-
)
8579

8680
if "description" in t:
8781
t_desc = t["description"]

tests/unit/test_serializer.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,13 @@ def test_cds_json_serializer_sanitization(video_record_metadata):
191191
assert 'Safe content' in description
192192
# Keep safe HTML tags like <b>
193193
assert '<b>bold</b>' in description
194-
195-
# Remove everything in title
194+
195+
# Title: only unescape, no HTML tag removal
196196
title = result['metadata']['title']['title']
197-
assert '<script>' not in title
198-
assert '</script>' not in title
199197
assert 'Test' in title and 'Title' in title
200-
assert '<b>' not in title
201-
202-
# --- Translations checks ---
198+
assert '<b>bold</b>' in title
199+
200+
# Translations: descriptions sanitized, titles only unescaped
203201
translations = result['metadata']['translations']
204202
for tr in translations:
205-
# description
206203
assert '<script>' not in tr['description']
207-
# title
208-
assert '<script>' not in tr['title']['title']
209-
assert '<b>' not in tr['title']['title']
210-

0 commit comments

Comments
 (0)