1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Refs #30686 -- Fixed text truncation for negative or zero lengths.

This commit is contained in:
David Smith
2024-02-06 20:52:52 +01:00
committed by Mariusz Felisiak
parent 3e820d10f8
commit 70f39e46f8
3 changed files with 10 additions and 2 deletions

View File

@@ -104,6 +104,8 @@ class Truncator(SimpleLazyObject):
"""
self._setup()
length = int(num)
if length <= 0:
return ""
text = unicodedata.normalize("NFC", self._wrapped)
# Calculate the length to truncate to (max length - end_text length)
@@ -144,6 +146,8 @@ class Truncator(SimpleLazyObject):
"""
self._setup()
length = int(num)
if length <= 0:
return ""
if html:
return self._truncate_html(length, truncate, self._wrapped, length, True)
return self._text_words(length, truncate)