summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorDavid Smith <smithdc@gmail.com>2024-02-06 20:52:52 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2024-02-07 05:18:35 +0100
commit70f39e46f86b946c273340d52109824c776ffb4c (patch)
tree59c7d77d33d8fd61b467107029c5f3fdef27f742 /django/utils
parent3e820d10f81ea9d0576633734c2ebd2621575cbe (diff)
Refs #30686 -- Fixed text truncation for negative or zero lengths.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/text.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/django/utils/text.py b/django/utils/text.py
index 295f919b51..374fd78f92 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -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)