Skip to content

Commit cd843dc

Browse files
committed
fix: prevent invalid HTML by discarding incomplete tags during text truncation
1 parent f0930d0 commit cd843dc

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

app/main/views/jobs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ def _truncate_text_preserving_markup(text, length):
6060
"""Truncate text while preserving Markup type if present."""
6161
is_markup = isinstance(text, Markup)
6262
truncated = unicode_truncate(str(text), length)
63+
64+
# If truncation ends between '<' and '>', discard the incomplete tag.
65+
if truncated.rfind("<") > truncated.rfind(">"):
66+
truncated = truncated[: truncated.rfind("<")]
67+
6368
return Markup(truncated) if is_markup else truncated
6469

6570

0 commit comments

Comments
 (0)