Return initial text when length is negative
authorThierry Florac <tflorac@ulthar.net>
Fri, 13 Nov 2020 12:52:53 +0100
changeset 445 98b00191ce4f
parent 444 72ceed22e639
child 446 181e3bb4bda3
Return initial text when length is negative
src/pyams_utils/text.py
--- a/src/pyams_utils/text.py	Fri Nov 13 12:51:19 2020 +0100
+++ b/src/pyams_utils/text.py	Fri Nov 13 12:52:53 2020 +0100
@@ -53,9 +53,11 @@
     'This is a long&#133;'
     >>> get_text_start('This is a long string', 20, 7)
     'This is a long string'
+    >>> get_text_start('This is a long string', -1)
+    'This is a long string'
     """
     result = text or ''
-    if length > len(result):
+    if (length < 0) or (length > len(result)):
         return result
     index = length - 1
     text_length = len(result)